report
report.Rmd
library(saferDev)
Datasets
string1 <- "THIS IS A LOG"
vec1 <- 1:6 # vector of integers
vec2 <- letters[1:9] # vector of characters
mat1 <- matrix(vec1, nrow = 2, ncol = 3, byrow = TRUE) # matrix of integer having 2 rows and 3 columns
dimnames(mat1) <- list(c("Row 1","Row 2"), c("C1", "C2", "C3"))
mat2 <- mat1
mode(mat2) <- "character"
t1 <- table(mat1) # 1D table
vec3 <- as.vector(t1)
names(vec3) <- letters[1:6] # vector with names
t2 <- table(vec2, vec2) # 2D table
l1 <- list(vec1, vec2) # list
Datasets info
string1 # string
> [1] "THIS IS A LOG"
vec1 # vector of integers
> [1] 1 2 3 4 5 6
vec2 # vector of characters
> [1] "a" "b" "c" "d" "e" "f" "g" "h" "i"
vec3 # vector of integers with names. No more [1] in front of values
> a b c d e f
> 1 1 1 1 1 1
mat1 # matrix of integers with the row names
> C1 C2 C3
> Row 1 1 2 3
> Row 2 4 5 6
mat2 # matrix of characters with the row names
> C1 C2 C3
> Row 1 "1" "2" "3"
> Row 2 "4" "5" "6"
t1 # 1D table
> mat1
> 1 2 3 4 5 6
> 1 1 1 1 1 1
t2 # 2D table
> vec2
> vec2 a b c d e f g h i
> a 1 0 0 0 0 0 0 0 0
> b 0 1 0 0 0 0 0 0 0
> c 0 0 1 0 0 0 0 0 0
> d 0 0 0 1 0 0 0 0 0
> e 0 0 0 0 1 0 0 0 0
> f 0 0 0 0 0 1 0 0 0
> g 0 0 0 0 0 0 1 0 0
> h 0 0 0 0 0 0 0 1 0
> i 0 0 0 0 0 0 0 0 1
l1 # list
> [[1]]
> [1] 1 2 3 4 5 6
>
> [[2]]
> [1] "a" "b" "c" "d" "e" "f" "g" "h" "i"
Simple examples
report(data = string1, path = ".") # print the input into the output file in the path
report(data = vec1, path = ".") # idem
report(data = vec2, path = ".") # idem
report(data = vec3, path = ".") # idem
report(data = mat1, path = ".") # idem
report(data = mat2, path = ".") # idem. We cannot see that it is mode character (see noquote below)
report(data = t1, path = ".") # idem
report(data = t2, path = ".") # idem
report(data = l1, path = ".") # idem
Argument output
report(data = vec1, output = "test.txt", path = ".") # print the vector vec1 into the output file named "test.txt" in the path
Argument overwrite
report(data = vec2, overwrite = TRUE, output = "test.txt", path = ".") # if the file exists, the output file content will be erased before printing
> Error:
>
> ================
>
> ERROR IN saferDev::report().
>
> FILE DEFINED BY THE path AND output ARGUMENTS
> ./test.txt
> ALREADY EXISTS AND CANNOT BE OVERWRITTEN.
> PLEASE:
> REMOVE THE FILE
> OR CHANGE THE NAME OF THE output ARGUMENT
> OR SET THE overwrite ARGUMENT TO FALSE TO APPEND IN THE EXISTING FILE.
>
>
> ================
Argument rownames_kept
report(
data = mat1,
rownames_kept = TRUE,
path = "."
) # keep the row names when print the matrix mat1 in the file
report(
data = mat1,
rownames_kept = FALSE,
path = "."
) # remove the row names
report(
data = t1,
rownames_kept = TRUE,
path = "."
) # keep the row names when print the table t1 in the file
report(
data = t1,
rownames_kept = FALSE,
path = "."
) # remove the row names
report(
data = t2,
rownames_kept = TRUE,
path = "."
) # keep the row names when print the table t2 in the file
report(
data = t2,
rownames_kept = FALSE,
path = "."
) # remove the row names
Argument vector_cat
report(
data = vec3,
vector_cat = TRUE,
path = "."
) # print a vector of length > 1 using cat() instead of capture.output() : names are lost.
Argument noquote
report(
data = mat2,
noquote = FALSE,
path = "."
) # quote are kept for the characters.
Argument safer_check
report(
data = vec1,
safer_check = TRUE
) # check if the package is in the computer, safer_check = TRUE, checkings are performed before main code running
> Error:
>
> ================
>
> ERROR IN saferDev::report().
>
> FOLLOWING ARGUMENT HAS NO DEFAULT VALUE AND REQUIRE ONE:
> path
>
> ================
Argument lib_path and error_text
report(
data = vec1,
lib_path = ".", # absolute pathways of the directories containing the required packages if not in the default directories.
error_text = "TEXT ADDED" # add information in error messages returned by the function.
)
> Error:
>
> ================
>
> ERROR IN saferDev::report()TEXT ADDED
>
> FOLLOWING ARGUMENT HAS NO DEFAULT VALUE AND REQUIRE ONE:
> path
>
> ================
All the arguments
report(
data = mat2,
output = "test2.txt",
path = ".",
overwrite = TRUE,
rownames_kept = TRUE,
vector_cat = TRUE,
noquote = FALSE,
sep = 4,
safer_check = TRUE, # perform some "safer" checks? Warning : always set this argument to FALSE if all_args_here() is used inside another safer function.
lib_path = NULL, # absolute pathways of the directories containing the required packages if not in the default directories.
error_text = "" # add information in error messages returned by the function.
)
# matrix mat1 will be print in the file "text2.txt" in the path, with quote and row names being kept, and 4 lines after printing data