christopherlang · GitHub

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

Read the original on github.com ↗