read.csv.sql {sqldf} | R Documentation |
Read a file into R filtering it with an sql statement. Only the filtered portion is processed by R so that files larger than R can otherwise handle can be accommodated.
read.csv.sql(file, sql = "select * from file", header = TRUE, sep = ",", row.names, eol, skip, dbname = tempfile(), ...) read.csv2.sql(file, sql = "select * from file", header = TRUE, sep = ";", row.names, eol, skip, dbname = tempfile(), ...)
file |
As in read.csv .
|
sql |
character string holding an SQL statement. The table representing the
file should be referred to as file .
|
header |
As in read.csv .
|
sep |
As in read.csv .
|
row.names |
As in read.csv .
|
eol |
Character which ends line. |
skip |
Skip indicated number of lines in input file. |
dbname |
As in sqldf except that the default is tempfile() .
|
... |
Passed to sqldf .
|
Reads the indicated file into an sql database creating the database if it does not already exist. Then it applies the sql statement returning the result as a data frame. If the database did not exist prior to this statement it is removed.
Note that it uses facilities of SQLite
to read the file
which are intended for speed and therefore
not as flexible as in R. For example, it does not
recognize quoted fields as special but will regard the quotes as
part of the field. See the
sqldf
help for more information.
read.csv2.sql
is like read.csv.sql
except
the default sep
is ";"
.
If the sql statement is a select statement then a data frame is returned.
## Not run: write.table(iris, "iris.csv", sep = ",", quote = FALSE, row.names = FALSE) iris2 <- read.csv.sql("iris.csv", sql = "select * from file where Sepal.Length > 5") ## End(Not run)