Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem using log function when dplyr is connected to SQLite #1330

Closed
christopherlang opened this issue Aug 19, 2015 · 0 comments
Closed

Problem using log function when dplyr is connected to SQLite #1330

christopherlang opened this issue Aug 19, 2015 · 0 comments

Comments

@christopherlang
Copy link

I'm having issues using the log function in mutate when the source is connect to a SQLite backend

Example 1
dbSource <- src_sqlite(":memory:",create=T)
dbTable <- copy_to(dbSource,iris)

dbTable %>%
  mutate(SepalLengthTest=log(Sepal.Length))
Error Message
Error: Invalid number of args to SQL LOG. Expecting 2
Example 2
dbTable %>%
  mutate(SepalLengthTest=log(Sepal.Length,exp(1))
Error Message
Error in sqliteSendQuery(con, statement, bind.data) : 
  error in statement: wrong number of arguments to function LOG()

Here is is my findings when I was investigating this:

  • translate_sql() accepts log(Sepal.Length,exp(1)) as valid, but doesn't accept log(Sepal.Length). It gives the same error message as example 1
  • If I directly use RSQLite::dbGetQuery (a separate SQLite database, with iris loaded) with the following SQL statement SELECT LOG([Sepal.Length]) FROM [iris], it works as expected, after calling initExtension on the connection object
  • dplyr calls initExtension inside src_sqlite function call, so it should work the same as RSQLite::dbGetQuery

It looks like the extension loaded into SQLite has a log function, but it only accepts one argument, the column to apply the function to. But dplyr expects the log function to have 2 arguments, conflicting with what SQLite expects

I am just wondering whether this is a bug or I'm doing this incorrectly

I tested and got those error messages on Mac OS X 10.10.4, Windows 7 64-bit, and Windows 10 64-bit, using R v3.2.1 64-bit, dplyr v0.4.2, RSQLite v1.0.0. Here is my sessionInfo dump on my Mac

> sessionInfo()
R version 3.2.1 (2015-06-18)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.10.4 (Yosemite)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] dplyr_0.4.2

loaded via a namespace (and not attached):
 [1] lazyeval_0.1.10  magrittr_1.5     R6_2.0.1         assertthat_0.1   parallel_3.2.1  
 [6] DBI_0.3.1        tools_3.2.1      Rcpp_0.11.6      RSQLite_1.0.0    nycflights13_0.1
@hadley hadley closed this as completed in e5f2a58 Aug 24, 2015
@lock lock bot locked as resolved and limited conversation to collaborators Jun 9, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant