Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to put SQL files in an R package?

Tags:

package

r

cran

I am working on an R package that builds on a postgreSQL database. Hence there are some.sql files that contain a recommended table structure for the corresponding database.

I wonder where to put these files if I want to build a package (for CRAN)?

like image 477
Matt Bannert Avatar asked Aug 23 '13 10:08

Matt Bannert


People also ask

How do I use SQL data in R?

To use SQL, open an R Notebook in the RStudio IDE under the File > New File menu. Start a new code chunk with {sql} , and specify your connection with the connection=con code chunk option. If you want to send the query output to an R dataframe, use output.

Can R read SQL File?

The RStudio IDE has direct integration with . sql files. You can open, edit, and test those file types inside RStudio.

Can you use R and SQL together?

Not only can you easily retrieve data from SQL Sources for analysis and visualisation in R, but you can also use SQL to create, clean, filter, query and otherwise manipulate datasets within R, using a wide choice of relational databases. There is no reason to abandon your hard-earned SQL skills!

Is SQL better than R?

SQL is a special-purpose language used for accessing data. For most tasks, SQL is more efficient than Python or R. R is a language for statistical computing. It's different from Python in that is has a different syntax and different data types.


1 Answers

maybe put them in folder "inst" (top level), like inst/sql

then the user or a function of yours could access files there with

base <- system.file('sql', package='bannertpackage')
sqls <- dir(base, "*sql", f=TRUE)

and execute them

http://cran.r-project.org/doc/manuals/R-exts.html#Package-subdirectories

The contents of the inst subdirectory will be copied recursively to the installation directory. Subdirectories of inst should not interfere with those used by R (currently, R, data, demo, exec, libs, man, help, html and Meta, and earlier versions used latex, R-ex). The copying of the inst happens after src is built so its Makefile can create files to be installed.

There will be a top folder in the library folder called sql which is nice, and you can access it from R, which is what you need.

like image 192
Ido Tamir Avatar answered Oct 11 '22 17:10

Ido Tamir