Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R: read contents of text file as a query?

Tags:

r

Using R, I just want to read the contents of a file into a variable like:

query <- read_file_contents('biglongquery.sql')

As to avoid putting, well, big long queries in the R script itself. I do not want to read in data like CSV (e.g. read.tables), etc- just the raw text.

like image 780
Wells Avatar asked Aug 27 '10 00:08

Wells


People also ask

How do I get SQL query 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.

What is the function used in R to read delimited file?

Example 1: Using read. delim() function to read a space-separated text file. The read. delim() function is used to read delimited text files in the R Language.


1 Answers

x <- paste(scan("foo.sql",what="",sep="\n",blank.lines.skip=FALSE),collapse="\n")
like image 148
Joshua Ulrich Avatar answered Sep 29 '22 16:09

Joshua Ulrich