Search code examples
rrsqlite

How to install package RSQLite.extfuns in R


I have a problem with installing package RSQLite.extfuns. I get error:

package ‘RSQLite.extfuns’ is not available (for R version 3.4.2)

I tried to do it manually by downloading file from https://cran.r-project.org/src/contrib/Archive/RSQLite.extfuns/ but also with negative effects. Can anyone solve my problem?


Solution

  • Those functions are now in RSQLite itself. Invoke the initExtension command to access them. This example uses the variance function from the extfuns:

    library(RSQLite)
    
    m <-dbDriver("SQLite")
    con <- dbConnect(m, dbname = ":memory:")
    
    initExtension(con)  # access extfuns
    
    dbWriteTable(con, 'BOD', BOD, row.names = FALSE)
    
    dbGetQuery(con, 'select variance(demand) from BOD')
    ##   variance(demand)
    ## 1         21.44267
    
    dbDisconnect(con)
    

    Also note that sqldf loads them automatically so you don't have to do anything special if you are using it:

    library(sqldf)
    
    sqldf('select variance(demand) from BOD')
    ##   variance(demand)
    ## 1         21.44267