r-dbi

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 <-

How to write binary data into SQLite with R DBI's dbWriteTable()?

浪子不回头ぞ 提交于 2019-12-05 19:59:57
For instance, how to execute the equivalent following SQL (which inserts into a BINARY(16) field) INSERT INTO Table1 (MD5) VALUES (X'6717f2823d3202449201145073ab871A'),(X'6717f2823d3202449301145073ab371A') using dbWriteTable() ? Doing dbWriteTable(db, "Table1", data.frame(MD5 = "X'6717f2823d3202449201145073ab871A'", ...), append = T, row.names = F) doesn't seem to work - it writes the values as text. In the end, I'm going to have a big data.frame of hashes that I want to write, and so perfect for using dbWriteTable . But I just can't figure out how to INSERT the data.frame into binary database

Connect to MSSQL using DBI

爱⌒轻易说出口 提交于 2019-12-05 07:14:24
I can not connect to MSSQL using DBI package. I am trying the way shown in package itself m <- dbDriver("RODBC") # error Error: could not find function "RODBC" # open the connection using user, passsword, etc., as # specified in the file \file{\$HOME/.my.cnf} con <- dbConnect(m, dsn="data.source", uid="user", pwd="password")) Any help appreciated. Thanks It looks like there used to be a RODBC driver for DBI, but not any more: http://cran.r-project.org/src/contrib/Archive/DBI.RODBC/ A bit of tweaking has got this to install in a version 3 R but I don't have any ODBC sources to test it on. But m

How to spread tbl_dbi and tbl_sql data without downloading to local memory

不想你离开。 提交于 2019-12-04 12:59:36
I am working with large datasets and tidyr's spread usually gives me error messages suggesting failure to obtain memory to perform the operation. Therefore, I have been exploring dbplyr . However, as it says here , and also shown below, dbplyr::spread() does not work. My question here is whether there is another way to accomplish what tidyr::spread does while working with tbl_dbi and tbl_sql data without downloading to local memory. Using sample data from here , below I present what I get and what I would like to do and get. #sample tbl_dbi and tbl_sql data df_sample <- tribble(~group1,

How to connect R to MySQL? Failed to connect to database: Error: Plugin caching_sha2_password could not be loaded

让人想犯罪 __ 提交于 2019-12-04 09:29:25
I recently installed MySQL on my computer and am trying to connect RStudio to MySQL. I followed instructions in a book as well as instructions here . However, whenever I use dbConnect() or src_mysql in RStudio , I get this error message: Error in .local(drv, ...) : Failed to connect to database: Error: Plugin caching_sha2_password could not be loaded: The specified module could not be found For example, I might login to MySQL using the command prompt in Windows mysql -u username -p and create a database as follows CREATE DATABASE myDatabase; and then in RStudio: library(RMySQL) db <- dbConnect

Can I run an SQL update statement using only dplyr syntax in R

情到浓时终转凉″ 提交于 2019-12-04 03:13:42
I need to update column values conditionnaly on other columns in some PostgreSQL database table. I managed to do it writing an SQL statement in R and executing it with dbExecute from DBI package. library(dplyr) library(DBI) # Establish connection with database con <- dbConnect(RPostgreSQL::PostgreSQL(), dbname = "myDb", host="localhost", port= 5432, user="me",password = myPwd) # Write SQL update statement request <- paste("UPDATE table_to_update", "SET var_to_change = 'new value' ", "WHERE filter_var = 'filter' ") # Back-end execution con %>% dbExecute(request) Is it possible to do so using

RMySQL system error: 10060

一笑奈何 提交于 2019-12-03 17:39:33
问题 I have a project with a connection that was working properly on the same device. I suddenly got the error below. And I could connect from the same device through MySQL workbench. What could be the reason? library(RMySQL) con <- dbConnect(RMySQL::MySQL(), host = "xxx", dbname="yyy", user = "zzz", password = "############") Error in .local(drv, ...) : Failed to connect to database: Error: Lost connection to MySQL server at 'reading authorization packet', system error: 10060 And here's the

How to use dynamic values while executing SQL scripts in R

混江龙づ霸主 提交于 2019-12-01 11:35:45
My R workflow now involves dealing with a lot of queries ( RPostgreSQL library). I really want to make code easy to maintain and manage in the future. I started loading large queries from separate .SQL files ( this helped) and it worked great. Then I started using interpolated values ( that helped) which means that I can write SELECT * FROM table WHERE value = ?my_value; and (after loading it into R) interpolate it using sqlInterpolate(ANSI(), query, value = "stackoverflow") . What happens now is I want to use something like this SELECT count(*) FROM ?my_table; but how can I make it work?

How to use dynamic values while executing SQL scripts in R

别等时光非礼了梦想. 提交于 2019-12-01 09:27:12
问题 My R workflow now involves dealing with a lot of queries ( RPostgreSQL library). I really want to make code easy to maintain and manage in the future. I started loading large queries from separate .SQL files (this helped) and it worked great. Then I started using interpolated values (that helped) which means that I can write SELECT * FROM table WHERE value = ?my_value; and (after loading it into R) interpolate it using sqlInterpolate(ANSI(), query, value = "stackoverflow") . What happens now

Can't connect to AWS Redshift using RPostgreSQL

*爱你&永不变心* 提交于 2019-11-30 20:27:57
问题 I'm not able to connect to my AWS Redshift database using RPostgreSQL. Does anyone have an example of code that would work? library (RPostgreSQL) drv <- dbDriver("PostgreSQL") conn <- dbConnect(drv, "database.us-east-1.redshift.amazonaws.com", "jeffz", "PsWrd123") Error in postgresqlNewConnection(drv, ...) : RS-DBI driver: (could not connect database.us-east-1.redshift.amazonaws.com@PsWrd123 on dbname "database.us-east-1.redshift.amazonaws.com" Windows 7 postgresql-8.4-703.jdbc4 in drivers