Description Usage Arguments Details Value Note Author(s) See Also Examples
Imports a text or Stata file to data.table, automatically converting dates
1 2 3 4 |
filename |
a single filename or path to a text file, Stata file, gz compressed text file or a zip file containing one file. |
datecolnames |
an argument passed to |
verbose |
whether to print information about the file loaded |
sep |
a single delimiter character. If NULL, the function will try to detect it (, ; or TAB) from the first line. |
zipname |
path to a zip file. This is only required if the zip file
contains more than one file, otherwise the path to the zip file
can be supplied as the |
key |
a character vector of key column names, to set the data.table key |
convertLogical |
whether to convert 1 / 0 columns to logical |
fread |
whether to use the new |
nrows |
number of rows to import, default (NULL) is to import all rows. |
... |
other arguments to pass to |
A convenience function for importing a text file, including handling zip compressed files, automatically detecting the delimiter and converting dates.
A data.table containing the imported data.
In the future this function may be updated to take advantage of the new fread function in the data.table package.
Anoop Shah
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | # Import a test dataset
data(test_data)
tempfile <- paste(tempdir(), '/tmp.csv', sep = '')
write.csv(test_data, tempfile, row.names = FALSE)
# Default (fread = TRUE)
importDT(tempfile)
# Using the older read.delim function
importDT(tempfile, fread = FALSE)
# Limiting the number of rows
importDT(tempfile, nrows = 3)
# Convert to FFDF
as.ffdf(importDT(tempfile))
# Importing another test dataset
data(test_import)
write.csv(test_import, tempfile, row.names = FALSE)
importDT(tempfile)
# datenotok is not converted because of an error
str(importDT(tempfile))
# Importing only one row (nrows is an argument to read.delim)
importDT(tempfile, nrows = 1)
unlink(tempfile)
# Importing Stata file
tempstata <- paste(tempdir(), '/tmp.dta', sep = '')
write.dta(test_data, tempstata)
importDT(tempstata)
unlink(tempstata)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.