rsqlite

(R) Error when trying to load the SQLDF package

十年热恋 提交于 2020-03-05 00:26:59
问题 I have been having some trouble running the following code: install.packages("sqldf",dep=TRUE) library(sqldf) install.packages("RSQLite",dep=TRUE) library(RSQLite) After running this, my intention is to use the sqldf function to run some queries, but I've gotten stuck on an error I'm not sure how to solve and I've had trouble finding any other answers on Stack Overflow that could be helpful. The following is the error I receive after running the first line: Loading required package: RSQLite

Appending to existing SQLite table when addition has fewer columns, without reading database into R

好久不见. 提交于 2019-12-24 02:39:16
问题 Is there some simple way, either on the SQL side or on the R side, to append a data.frame to an existing table that has more columns? The missing columns should just be filled in with NAs. Bonus points if it gracefully handles table 2 having more columns than table 1? library(RSQLite) # Create db <- dbConnect( SQLite(), dbname="~/temp/test.sqlite" ) # Write test set.seed(1) n <- 1000 testDat <- data.frame(key=seq(n), x=runif(n),y=runif(n),g1=sample(letters[1:10],n,replace=TRUE),g2=rep(letters

Error in rsqlite_send_query(conn@ptr, statement) : near “(”: syntax error

安稳与你 提交于 2019-12-11 08:53:40
问题 The following line of code: sqldf("UPDATE q1_sql_1 SET MONTH_YEAR = RIGHT(MONTH_YEAR, LEN(MONTH_YEAR) - 4)") Shows this error: Error in rsqlite_send_query(conn@ptr, statement) : near "(": syntax error 回答1: Use length and rightstr . For the functions available in SQLite see: https://www.sqlite.org/lang_corefunc.html and for the contributed functions that RSQLite also makes available: https://github.com/ggrothendieck/sqldf#example-15-use-of-rsqliteextfuns-library-functions 来源: https:/

Loading SQLite table in R with RSQLite

允我心安 提交于 2019-12-10 10:51:02
问题 I had this function I used to load a SQLite table sqLiteConnect <- function(database, table) { library(DBI) library(RSQLite) con <- dbConnect("SQLite", dbname = database) query <- dbSendQuery(con, paste("SELECT * FROM ", table, ";", sep="")) result <- fetch(query, n = -1, encoding="utf-8") dbClearResult(query) dbDisconnect(con) return(result) } But now it seams it generates an error album <- sqLiteConnect("~/Downloads/ChinookDatabase1.3_Sqlite/Chinook_Sqlite.sqlite","Album") Error in

How to import tab delimited data to sqlite using RSQLite?

我的未来我决定 提交于 2019-12-08 13:50:42
问题 I'd like to import a bunch of large text files to a SQLite db using RSQLite. If my data were comma delimited, I'd do this: library(DBI) library(RSQLite) db <- dbConnect(SQLite(), dbname = 'my_db.sqlite') dbWriteTable(conn=db, name='my_table', value='my_file.csv') But how about with '\t' -delimited data? I know I could read the data into an R data.frame and then create the table from that, but I'd like to go straight into SQLite, since there are lots of large files. When I try the above with

R dbGetQuery with dynamic string

你离开我真会死。 提交于 2019-12-07 22:26:13
问题 From This post and This post, I got a way to write an rsqlite dynamic command. However, it doesn't work for me. My data looks like: Id <- c(34, 22, 86) sqlcmd <- paste("select col1, col2 from DB where ItemId =", Id, sep="") Df <- dbGetQuery(conn, sqlcmd) My sqlcmd gives me a list of strings as "select col1, col2 from DB where STOREID =34" "select col1, col2 from DB where STOREID =22" "select col1, col2 from DB where STOREID =86" However, when I pass sqlcmd to dbGetQuery , it only returns data

R dbGetQuery with dynamic string

点点圈 提交于 2019-12-06 07:21:09
From This post and This post , I got a way to write an rsqlite dynamic command. However, it doesn't work for me. My data looks like: Id <- c(34, 22, 86) sqlcmd <- paste("select col1, col2 from DB where ItemId =", Id, sep="") Df <- dbGetQuery(conn, sqlcmd) My sqlcmd gives me a list of strings as "select col1, col2 from DB where STOREID =34" "select col1, col2 from DB where STOREID =22" "select col1, col2 from DB where STOREID =86" However, when I pass sqlcmd to dbGetQuery , it only returns data with ItemId = 34 , which is the first element in the Id list. I'm wondering if anyone has any ideas

Loading SQLite table in R with RSQLite

半腔热情 提交于 2019-12-06 04:58:07
I had this function I used to load a SQLite table sqLiteConnect <- function(database, table) { library(DBI) library(RSQLite) con <- dbConnect("SQLite", dbname = database) query <- dbSendQuery(con, paste("SELECT * FROM ", table, ";", sep="")) result <- fetch(query, n = -1, encoding="utf-8") dbClearResult(query) dbDisconnect(con) return(result) } But now it seams it generates an error album <- sqLiteConnect("~/Downloads/ChinookDatabase1.3_Sqlite/Chinook_Sqlite.sqlite","Album") Error in (function (classes, fdef, mtable) : unable to find an inherited method for function ‘dbConnect’ for signature ‘

Adding column to sqlite database

好久不见. 提交于 2019-12-06 04:39:09
问题 I am trying to add a vector which I generated in R to a sqlite table as a new column. For this I wanted to use dplyr (I installed the most recent dev. version along with the dbplyr package according to this post here). What I tried: library(dplyr) library(DBI) #creating initial database and table dbcon <- dbConnect(RSQLite::SQLite(), "cars.db") dbWriteTable(dbcon, name = "cars", value = cars) cars_tbl <- dplyr::tbl(dbcon, "cars") #new values which I want to add as a new column new_values <-

sqldf : create table from data frame error: “no such table”. and two tables created instead of one

一曲冷凌霜 提交于 2019-12-06 02:28:09
问题 I've recently upgraded R, RSQLite, and sqldf (versions below). Normally: sqldf('create table foo as select * from bar', db = 'test.db') should create a table called 'foo' in an attached sqlite database, using data frame 'bar' if it exists to load the new table. Instead, I'm getting a 'no such table' error, and also when I look at the database there are both 'foo' and 'bar' tables created. Reproducible example: library(RSQLite) library(sqldf) mydb = 'test.db' ## remove file if it exists system