Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 995801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:46:44+00:00 2026-05-16T06:46:44+00:00

I am using a the RSQLite library in R in to manage a data

  • 0

I am using a the RSQLite library in R in to manage a data set that is too large for RAM. For each regression I query the database to retrieve a fiscal year at a time. Now I have the fiscal year hard-coded:

data.annual <- dbGetQuery(db, "SELECT * FROM annual WHERE fyear==2008")

I would like to make the fiscal year (2008 above) to make changes a bit easier (and fool-proof). Is there a way that I can pass a variable into SQL query string? I would love to use:

fiscal.year <- 2008
data.annual <- dbGetQuery(db, "SELECT * FROM annual WHERE fyear==fiscal.year")
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T06:46:44+00:00Added an answer on May 16, 2026 at 6:46 am

    SQLite will only see the string passed down for the query, so what you do is something like

      sqlcmd <- paste("SELECT * FROM annual WHERE fiscal=", fiscal.year, sep="")
      data.annual <- dbGetQuery(db, sqlcmd)
    

    The nice thing is that you can use this the usual way to unwind loops. Forgetting for a second that you have ram restrictions, conceptually you can do

      years <- seq(2000,2010)
      data <- lapply(years, function(y) {
         dbGetQuery(db, paste("SELECT * FROM annual WHERE fiscal=", y, sep="")
      }
    

    and now data is a list containing all your yearly data sets. Or you could keep the data, run your regression and only store the summary object.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to join two tables in an SQLite database using RSQLite When
How do you write a SQL query with a date using RSQLite. Here is
I'm using the RSQLite package to make queries to a local SQLite database, and
Using Trigger.io's barcode api in an application that only contains boilerplate HTML and the
Using the example here as a starting point, I set out to customize my
Using the following as an example (with $db being a previously created database connection
Using the following database table structure: Order Table: OrderId OrderName OrderItem Table: OrderId ItemId
Using Visual SourceSafe's Open SourceSafe Database... command, there is an option at the bottom
Using the Excel 2010 OleDb driver and an OleDbConnection I can query and manipulate
Using CMake I want to check if a particular function (cv::getGaborKernel) from OpenCV library

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.