# Create some temporary files
tmpcsv <- tempfile(fileext="csv")
tmp2csv <- tempfile(fileext="csv")
tmpyaml <- tempfile(fileext="yaml")
# Generate test data
ntest <- 10
column_types <- c("integer", "integer", "double", "string")
testdata <- data.frame(
a = 1:ntest,
b = sample(1:2, ntest, replace=TRUE),
c = round(runif(ntest), 13),
d = sample(c("jan", "pier", "tjores", "corneel"), ntest, replace=TRUE)
)
# Write test data to csv file
write.table(testdata, file=tmpcsv, row.names=FALSE, col.names=FALSE, sep=',')
# Create LaF-object
laf <- laf_open_csv(tmpcsv, column_types=column_types)
# Write data model to file
write_dm(laf, tmpyaml)
# Read data model and open file
laf <- laf_open(read_dm(tmpyaml))
# Write test data to second csv file
write.table(testdata, file=tmp2csv, row.names=FALSE, col.names=FALSE, sep=',')
# Read data model and open second file, demonstrating the use of the optional
# arguments to laf_open
laf2 <- laf_open(read_dm(tmpyaml), filename=tmp2csv)
# Cleanup
file.remove(tmpcsv)
file.remove(tmp2csv)
file.remove(tmpyaml)
Run the code above in your browser using DataLab