R Under development (unstable) (2023-11-16 r85542 ucrt) -- "Unsuffered Consequences" Copyright (C) 2023 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. > library("R.utils") 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.25.0 (2022-06-12 02:20:02 UTC) 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.utils v2.12.3 successfully loaded. See ?R.utils for help. Attaching package: 'R.utils' The following object is masked from 'package:utils': timestamp The following objects are masked from 'package:base': cat, commandArgs, getOption, isOpen, nullfile, parse, warnings > show <- methods::show > > # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > # General tests > # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > x <- letters[1:8] > x2 <- c(x[-1], "\n") > x3 <- x2[-1] > y <- as.list(x[1:3]) > > cat("mprint():\n") mprint(): > print(x) [1] "a" "b" "c" "d" "e" "f" "g" "h" > mprint(x) [1] "a" "b" "c" "d" "e" "f" "g" "h" > > print(y) [[1]] [1] "a" [[2]] [1] "b" [[3]] [1] "c" > mprint(y) [[1]] [1] "a" [[2]] [1] "b" [[3]] [1] "c" > > cat("mcat():\n") mcat(): > cat(x, "\n") a b c d e f g h > mcat(x, "\n") a b c d e f g h > > cat(x2) b c d e f g h > mcat(x2) b c d e f g h > > cat(x3, sep=",") c,d,e,f,g,h, > mcat(x3, sep=",") c,d,e,f,g,h, > > cat(x3, sep="\n") c d e f g h > mcat(x3, sep="\n") c d e f g h > > > cat("mstr():\n") mstr(): > str(x) chr [1:8] "a" "b" "c" "d" "e" "f" "g" "h" > mstr(x) chr [1:8] "a" "b" "c" "d" "e" "f" "g" "h" > > str(y) List of 3 $ : chr "a" $ : chr "b" $ : chr "c" > mstr(y) List of 3 $ : chr "a" $ : chr "b" $ : chr "c" > > cat("mshow():\n") mshow(): > show(x) [1] "a" "b" "c" "d" "e" "f" "g" "h" > mshow(x) [1] "a" "b" "c" "d" "e" "f" "g" "h" > > show(y) [[1]] [1] "a" [[2]] [1] "b" [[3]] [1] "c" > mshow(y) [[1]] [1] "a" [[2]] [1] "b" [[3]] [1] "c" > > cat("mprintf():\n") mprintf(): > printf("x=%d\n", 1:3) x=1 x=2 x=3 > mprintf("x=%d\n", 1:3) x=1 x=2 x=3 > > cat("mout():\n") mout(): > writeLines(x) a b c d e f g h > mout(writeLines(x)) a b c d e f g h > > > # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > # Tests related to closure > # - - - - - - - - - - - -- - - - - - - - - - - - - - - - - - > mfoo <- function(a=1) { + mprintf("a=%s\n", a) + } > > mbar <- function(...) { + mfoo(...) + } > > a <- 2 > mfoo(a) a=2 > mfoo(3) a=3 > > mbar(a) a=2 > mbar(3) a=3 > > > > # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > # Assert that "console" messages can be captured/sunk > # via stderr but not stdout > # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > res <- captureOutput({ mcat("Hello") }) Hello > str(res) chr(0) > stopifnot(length(res) == 0L) > > withSink({ mcat("Hello") }, file="foo.txt", type="message") > res <- readLines("foo.txt") > str(res) chr "Hello" > stopifnot(length(res) > 0L) > > proc.time() user system elapsed 0.29 0.14 0.40