R Under development (unstable) (2024-01-23 r85822 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > source("incl/start.R") Loading required package: R.oo Loading required package: R.methodsS3 R.methodsS3 v1.8.2 (2022-06-13 22:00:14 UTC) successfully loaded. See ?R.methodsS3 for help. R.oo v1.26.0 successfully loaded. See ?R.oo for help. Attaching package: 'R.oo' The following object is masked from 'package:R.methodsS3': throw The following objects are masked from 'package:methods': getClasses, getMethods The following objects are masked from 'package:base': attach, detach, load, save R.filesets v2.15.1 successfully loaded. See ?R.filesets for help. Attaching package: 'R.filesets' The following objects are masked from 'package:base': append, readLines > > message("*** Extending TabularTextFile") *** Extending TabularTextFile > > pathA <- system.file("exData", "dataSetA,original", package="R.filesets") > > # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > # Plain tab-delimited file > # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > tsf <- TabularTextFile("fileB,other,tags.dat", path=pathA) > print(tsf) TabularTextFile: Name: fileB Tags: other,tags Full name: fileB,other,tags Pathname: ../../lib/R.filesets/exData/dataSetA,original/fileB,other,tags.dat File size: 108 B (108 bytes) Number of data rows: 10 Columns [4]: 'x', 'y', 'fac', 'char' Number of text lines: 11 > > # Read all data > data <- readDataFrame(tsf) > str(data) 'data.frame': 10 obs. of 4 variables: $ x : int 1 1 1 1 1 2 2 2 2 3 $ y : int 1 2 5 6 10 12 7 43 9 12 $ fac : chr "A" "B" "D" "A" ... $ char: chr "r" "b" "g" "q" ... > > > > # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > # Custom tab-delimited file > # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > if (!is.element("covr", loadedNamespaces())) { + setConstructorS3("MyTabularTextFile", function(...) { + extend(TabularTextFile(...), "MyTabularTextFile") + }) + + setMethodS3("getDefaultColumnClassPatterns", "MyTabularTextFile", function(...) { + c("*"="NULL", "(x|y)"="integer") + }) + + tsfx <- MyTabularTextFile("fileB,other,tags.dat", path=pathA) + print(tsfx) + + rargs <- getReadArguments(tsfx) + print(rargs$colClasses) + stopifnot(rargs$colClasses["x"] == "integer", + rargs$colClasses["y"] == "integer", + rargs$colClasses["fac"] == "NULL", + rargs$colClasses["char"] == "NULL") + + datax <- readDataFrame(tsfx) + str(datax) + } MyTabularTextFile: Name: fileB Tags: other,tags Full name: fileB,other,tags Pathname: ../../lib/R.filesets/exData/dataSetA,original/fileB,other,tags.dat File size: 108 B (108 bytes) Number of data rows: 10 Columns [4]: 'x', 'y', 'fac', 'char' Number of text lines: 11 x y fac char "integer" "integer" "NULL" "NULL" 'data.frame': 10 obs. of 2 variables: $ x: int 1 1 1 1 1 2 2 2 2 3 $ y: int 1 2 5 6 10 12 7 43 9 12 > > source("incl/end.R") > > proc.time() user system elapsed 0.62 0.07 0.68