-2

I try to subset dataframe using sqlfd but it doesn't work. Can someone explain why? I have processed like this.

library(sqldf)
dataf <- read.csv("zert.csv")

agep & pwgt1 are columns of dataf

dd <- sqldf("select * from dataf where AGEP < 50 and pwgtp1")

Error in .local(drv, ...) :

Failed to connect to database: Error: Access denied for user 'rodrigue'@'localhost' (using password: NO) Error in !dbPreExists : invalid argument type

zx8754
  • 52,746
  • 12
  • 114
  • 209
  • 2
    Try it in a fresh session. Make sure you don't have any library statements in your `.Rprofile` . Try adding `verbose = TRUE` as an argument to `sqldf`. When posting to SO all inputs should be included so that it is reproducible by anyone else. – G. Grothendieck Feb 09 '16 at 14:04
  • 2
    In addition to @G.Grothendieck: [Info on how to give a reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610) – Jaap Feb 09 '16 at 14:07
  • THANK @G.Grothendieck and . despite your tips i don't find anything. when i try in the fresh session and add 'verbose = TRUE' as an argument to sqldf i have '> dd <- sqlfd("select * from dataf where AGEP < 50 and pwgtp1", verbose = TRUE)' '>sqldf: library(RMySQL)' '>sqldf: m <- dbDriver("MySQL")' 'Error in .local(drv, ...) : Failed to connect to database: Error: Access denied for user 'rodrigue'@'localhost' (using password: NO) Error in !dbPreExists : invalid argument type' – rodrigue djouontu Feb 10 '16 at 12:40
  • Yes, it did show somethinig. It showed that you have issued a library(MySQL) call which you did not show us. Was it your intention to use MySQL? Remove the call to library(MySQL) and just use it with SQLite or else read the documentation and set up MySQL to work with sqldf. – G. Grothendieck Feb 10 '16 at 13:13

1 Answers1

0

sqldf need a SQL Provider and in your comment it seems you have MYSQL and it needs password to connect.
therefor you need password option in sqldf function.
any way
let me give you a suggestion: forget SQL and believe R has itself syntax that more power full of SQL. R has more power full and fast package data.table. this is your answer more fast of any other way:

require(data.table)
Dt=fread('/path/to/File.csv',there are some useful options)
setkey(Dt,AGEP) # if it is huge file
ddf=Dt[AGEP<50 & pwgtp1,]
Hossein Vatani
  • 1,381
  • 14
  • 26