tests/TabularTextFile,huge.R

source("incl/start.R")

library("R.utils")  # writeDataFrame()

message("*** A huge TabularTextFile")

# Generate a large data frame
set.seed(42)
n <- 1e5
data <- data.frame(
  index = seq_len(n),
  x = runif(n),
  y = rnorm(n),
  symbol = sample(letters, size=n, replace=TRUE)
)

# Write to tab-delimited file
pathname <- tempfile(fileext=".tsv")
writeDataFrame(data, file=pathname)

# Setup tabular file
db <- TabularTextFile(pathname)
print(db)

# Read subset of the rows
n <- nbrOfRows(db)
data2 <- readDataFrame(db, rows=seq(from=1, to=n, length.out=0.10*n))
str(data2)

# Cleanup
file.remove(pathname)

source("incl/end.R")

Try the R.filesets package in your browser

Any scripts or data that you put into this service are public.

R.filesets documentation built on July 21, 2022, 5:11 p.m.