Reputation: 1560
I have a SQL query that I would like to ship with an R package I have built, but when I try to include it in the inst
or extdata
or data
folders inside my R package I don't know how to get the function to reference it. An example might be this: query file is myQuery.sql
runDbQuery = function(){
queryfile = 'folder/myQuery.sql'
query = readChar(queryfile, file.info(queryfile)$size)
require(RODBC)
channel <- odbcConnect("mydb", uid = "uid",
pwd = "pwd")
dbResults = sqlQuery(channel = channel, query = query, as.is = T)
close(channel)
return(dbResults)
}
Upvotes: 2
Views: 189
Reputation: 173577
I put .sql
files I use in packages in /inst/sql
and then get the path to them in functions via:
system.file("sql/myquery.sql",package = "mypackage")
Upvotes: 3