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.
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.
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.
x <- paste(scan("foo.sql",what="",sep="\n",blank.lines.skip=FALSE),collapse="\n")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With