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.
If you would like to contribute to this project, please see the CONTRIBUTING.md
file. Idea inspired by Eduardo Arino de la Rubia's fast_sample.
You can install the stable version from the HPCRAN using the usual install.packages()
:
install.packages("filesampler", repos="https://hpcran.org")
The development version is maintained on GitHub:
remotes::install_github("wrathematics/filesampler")
library(filesampler)
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:
vignette("filesampler", package="filesampler")
The C code in the src/filesampler
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:
src/filesampler/utils.h
Detailed explanations are contained there, but you will need:
printf()
)Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.