report
report.Rd
Log file function: print a character string or a data object into a same output file.
Usage
report(
data,
output = "log.txt",
path,
overwrite = FALSE,
rownames_kept = FALSE,
vector_cat = FALSE,
noquote = TRUE,
sep = 2,
safer_check = TRUE,
lib_path = NULL,
error_text = ""
)
Arguments
- data
Object to print in the output file. If NULL, nothing is done, with no warning.
- output
Single character string. Name of the output file.
- path
Single character string indicating the path where to write the output file.
- overwrite
Single logical value. If output file already exists and overwrite is TRUE, an error message is returned (no overwrite of existing file possible). Otherwise, the printing is appended (and the output file is created if it does not exist yet).
- rownames_kept
Single logical value. Defines whether row names have to be removed or in 2D objects. Warning: in 1D tables, names over the values are taken as row names, and are thus removed if rownames_kept is FALSE.
- vector_cat
Single logical value. If TRUE print a vector of length > 1 using cat() instead of capture.output(). Otherwise (default FALSE) the opposite. Names of values are not printed when TRUE
- noquote
Single logical value. If TRUE no quote are present for the characters.
- sep
Single non null and positive integer representing the number of empty lines after printed data.
- safer_check
Single logical value. Perform some "safer" checks? If TRUE, checkings are performed before main code running (see https://github.com/safer-r): 1) correct lib_path argument value 2) required functions and related packages effectively present in local R lybraries and 3) R classical operators (like "<-") not overwritten by another package because of the R scope. Must be set to FALSE if this fonction is used inside another "safer" function to avoid pointless multiple checkings.
- lib_path
Vector of characters specifying the absolute pathways of the directories containing the required packages for the function, if not in the default directories. Useful when R package are not installed in the default directories because of lack of admin rights. More precisely, lib_path is passed through the new argument of .libPaths() so that the new library paths are unique(c(new, .Library.site, .Library)). Warning: .libPaths() is restored to the initial paths, after function execution. Ignored if NULL (default) or if the safer_check argument is FALSE: only the pathways specified by the current .libPaths() are used for package calling.
- error_text
Single character string used to add information in error messages returned by the function, notably if the function is inside other functions, which is practical for debugging. Example: error_text = " INSIDE <PACKAGE_1>::<FUNCTION_1> INSIDE <PACKAGE_2>::<FUNCTION_2>.". If NULL, converted into "".
Examples
report(data = "THE FOLLOWING VECTOR IS:\n", output = "results.txt", path = ".", overwrite = TRUE, sep = 1)
report(data = 1:3, output = "results.txt", path = ".", overwrite = FALSE, rownames_kept = FALSE, vector_cat = FALSE, noquote = FALSE, sep = 2)
report(data = "THE FOLLOWING MATRIX IS:\n", output = "results.txt", path = ".", overwrite = FALSE, sep = 1)
report(data = matrix(1:5), output = "results.txt", path = ".", overwrite = FALSE, rownames_kept = FALSE, vector_cat = FALSE, noquote = FALSE, sep = 5)
report(data = "THE FOLLOWING DATA FRAME IS:\n", output = "results.txt", path = ".", overwrite = FALSE, sep = 1)
report(data = data.frame(A = 1:8, B = letters[1:8]), output = "results.txt", path = ".", overwrite = FALSE, rownames_kept = FALSE, vector_cat = FALSE, noquote = FALSE, sep = 1)