This is a simple R package to quickly read a random sample of lines of a flat text file (such as a csv) into R. This allows you to get a subsample into R without having to read the (possibly large) file into memory first.
The development version is maintained on GitHub, and can easily be installed by any of the packages that offer installations from GitHub:
### Pick your preference devtools::install_github("wrathematics/lineSampler") ghit::install_github("wrathematics/lineSampler") remotes::install_github("wrathematics/lineSampler")
library(lineSampler) ret <- sample_csv(file, p=.001)
There is also a
sample_lines() function for reading in (line) subsamples of unstructured text akin to
readLines(). See package vignette for more details.
For more information, including benchmarks and implementation details, please see the package vignette:
The C code in the
src/lineSampler tree of this package can easily be re-purposed for use outside of R with some minor modifications. The components that need to be edited can be found in the file:
Detailed explanations are contained there, but you will need:
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.