all_args_here(): more examples
all_args_here.Rmd
library(saferDev)Dataset
source("https://raw.githubusercontent.com/safer-r/saferDev/main/dev/other/test2.R") # function.
source("https://raw.githubusercontent.com/safer-r/.github/refs/heads/main/profile/backbone.R") # function.
FUN1 <- function(x, y){ # function.
code_for_col <- base::as.vector(
x = base::unlist(
x = base::mapply(
FUN = function(x, y){
base::rep(
x = y,
base::length(x = x)
)
},
x = x,
y = y,
MoreArgs = NULL,
SIMPLIFY = TRUE,
USE.NAMES = TRUE
),
recursive = TRUE,
use.names = TRUE
),
mode = "any"
)
# The code below is written without carriage return on purpose.
code_for_col2 <- base::as.vector(x = base::unlist(x = base::mapply(FUN = function(x, y){base::rep(x = y, base::length(x = x))}, x = x, y = y)))
middle_bracket <- base::do.call(what = base::c, args = code_for_col)
middle_bracket2 <- base::do.call(what = base::c, args = code_for_col, quote = FALSE, envir = base::parent.frame())
}
FUN2 <- function(x, y){ # function.
middle_bracket2 <- base::do.call(
what = base::c,
args = code_for_col,
quote = FALSE,
envir = base::parent.frame()
)
}Simple examples
# Example that returns an error.
all_args_here(mean)## Error:
##
## ================
##
## ERROR IN saferDev::all_args_here().
##
## CANNOT GET THE ARGUMENTS OF A FUNCTION THAT IS NOT ASSOCIATED TO ITS PACKAGE IN LINE 2:
##
## UseMethod("mean")
##
## PLEASE, RUN saferDev::colons_check(mean) FIRST,
## ADD THE MISSING <PACKAGE>::<FUNCTION> (OR <PACKAGE>:::<FUNCTION> FOR FUNCTION STARTING BY A DOT)
## AND RERUN saferDev::all_args_here(mean).
##
## ================
# Example that returns an error.
all_args_here(test2)## Error:
##
## ================
##
## ERROR IN saferDev:::.all_args_here_fill() INSIDE saferDev::all_args_here().
##
## THE TESTED FUNCTION test2 SEEMS TO HAVE A WRITING ERROR IN LINE 13 AND FUNCTION length.
## PLEASE, RUN THE TESTED FUNCTION FIRST.
##
## ================
# Example indicating missing arguments.
all_args_here(
x = FUN2
)##
## INSIDE FUN2(), ARGUMENTS ARE MISSING.
## LINE_NB FUN_NAME
## 1 2 do.call
## 2 6 parent.frame
## FUN_ARGS
## 1 do.call( what = base::c, args = code_for_col, quote = FALSE, envir = base::parent.frame() )
## 2 parent.frame()
## FUN_POS DEF_ARGS MISSING_ARG_NAMES
## 1 26 what, args, quote = FALSE, envir = parent.frame()
## 2 15 n = 1 n
## MISSING_ARGS STATUS
## 1 GOOD
## 2 n = 1 parent.frame(n = 1)
Arguments export, out_path,
df_name and overwrite
# Print the results into the res.tsv file written in the "." path,
# and overwrite if res.tsv already exists in ".".
all_args_here(
x = FUN2,
export = TRUE,
out_path = ".",
df_name = "res.tsv",
overwrite = TRUE
)##
## INSIDE FUN2(), ARGUMENTS ARE MISSING.
## RESULT EXPORTED IN:
## ./res.tsv
Argument safer_check
# Safer checkings are performed before main code running.
all_args_here(
x = FUN2,
safer_check = TRUE
)##
## INSIDE FUN2(), ARGUMENTS ARE MISSING.
## LINE_NB FUN_NAME
## 1 2 do.call
## 2 6 parent.frame
## FUN_ARGS
## 1 do.call( what = base::c, args = code_for_col, quote = FALSE, envir = base::parent.frame() )
## 2 parent.frame()
## FUN_POS DEF_ARGS MISSING_ARG_NAMES
## 1 26 what, args, quote = FALSE, envir = parent.frame()
## 2 15 n = 1 n
## MISSING_ARGS STATUS
## 1 GOOD
## 2 n = 1 parent.frame(n = 1)
Argument lib_path
# The "NOTGOOD" path does not exists.
all_args_here(
x = FUN2,
lib_path = "NOTGOOD"
)## Error:
##
## ================
##
## ERROR IN saferDev::all_args_here().
##
## THE DIRECTORY PATH INDICATED IN THE lib_path ARGUMENT DOES NOT EXIST:
## NOTGOOD
##
## ================
Argument error_text
# Add a text in error messages returned by all_args_here().
all_args_here(
x = FUN2,
lib_path = "NOTGOOD",
error_text = " === TEXT ADDED ==="
)## Error:
##
## ================
##
## ERROR IN saferDev::all_args_here() === TEXT ADDED ===
##
## THE DIRECTORY PATH INDICATED IN THE lib_path ARGUMENT DOES NOT EXIST:
## NOTGOOD
##
## ================
All the arguments
all_args_here(
x = FUN1, # R function.
export = FALSE, # export the data frame into a .tsv file?
out_path = ".", # pathway of the folder where to export the data frame.
df_name = "res.tsv", # name of the exported data frame file.
overwrite = FALSE, # overwrite potential df_name file already existing in out_path?
safer_check = TRUE, # perform some "safer" checks (see https://github.com/safer-r)?
lib_path = NULL, # where the required packages are if not in the default directories.
error_text = "" # add information in error messages returned by the function.
)##
## INSIDE FUN1(), ARGUMENTS ARE MISSING.
## LINE_NB FUN_NAME
## 1 2 as.vector
## 2 3 unlist
## 3 4 mapply
## 4 6 rep
## 5 8 length
## 6 23 as.vector
## 7 23 unlist
## 8 23 mapply
## 9 23 rep
## 10 23 length
## 11 24 do.call
## 12 25 do.call
## 13 25 parent.frame
## FUN_ARGS
## 1 as.vector( x = base::unlist( x = base::mapply( FUN = function(x, y){ base::rep( x = y, base::length(x = x) ) }, x = x, y = y, MoreArgs = NULL, SIMPLIFY = TRUE, USE.NAMES = TRUE ), recursive = TRUE, use.names = TRUE ), mode = "any" )
## 2 unlist( x = base::mapply( FUN = function(x, y){ base::rep( x = y, base::length(x = x) ) }, x = x, y = y, MoreArgs = NULL, SIMPLIFY = TRUE, USE.NAMES = TRUE ), recursive = TRUE, use.names = TRUE )
## 3 mapply( FUN = function(x, y){ base::rep( x = y, base::length(x = x) ) }, x = x, y = y, MoreArgs = NULL, SIMPLIFY = TRUE, USE.NAMES = TRUE )
## 4 rep( x = y, base::length(x = x) )
## 5 length(x = x)
## 6 as.vector(x = base::unlist(x = base::mapply(FUN = function(x, y){base::rep(x = y, base::length(x = x))}, x = x, y = y)))
## 7 unlist(x = base::mapply(FUN = function(x, y){base::rep(x = y, base::length(x = x))}, x = x, y = y))
## 8 mapply(FUN = function(x, y){base::rep(x = y, base::length(x = x))}, x = x, y = y)
## 9 rep(x = y, base::length(x = x))
## 10 length(x = x)
## 11 do.call(what = base::c, args = code_for_col)
## 12 do.call(what = base::c, args = code_for_col, quote = FALSE, envir = base::parent.frame())
## 13 parent.frame()
## FUN_POS DEF_ARGS
## 1 23 x, mode = "any"
## 2 11 x, recursive = TRUE, use.names = TRUE
## 3 11 FUN, ..., MoreArgs = NULL, SIMPLIFY = TRUE, USE.NAMES = TRUE
## 4 7 x, ...
## 5 7 x
## 6 24 x, mode = "any"
## 7 44 x, recursive = TRUE, use.names = TRUE
## 8 61 FUN, ..., MoreArgs = NULL, SIMPLIFY = TRUE, USE.NAMES = TRUE
## 9 95 x, ...
## 10 112 x
## 11 25 what, args, quote = FALSE, envir = parent.frame()
## 12 26 what, args, quote = FALSE, envir = parent.frame()
## 13 100 n = 1
## MISSING_ARG_NAMES
## 1
## 2
## 3
## 4
## 5
## 6 mode
## 7 recursive, use.names
## 8 MoreArgs, SIMPLIFY, USE.NAMES
## 9
## 10
## 11 quote, envir
## 12
## 13 n
## MISSING_ARGS
## 1
## 2
## 3
## 4
## 5
## 6 mode = "any"
## 7 recursive = TRUE, use.names = TRUE
## 8 MoreArgs = NULL, SIMPLIFY = TRUE, USE.NAMES = TRUE
## 9
## 10
## 11 quote = FALSE, envir = parent.frame()
## 12
## 13 n = 1
## STATUS
## 1 GOOD
## 2 GOOD
## 3 GOOD
## 4 GOOD
## 5 GOOD
## 6 as.vector(x = base::unlist(x = base::mapply(FUN = function(x, y){base::rep(x = y, base::length(x = x))}, x = x, y = y)), mode = "any")
## 7 unlist(x = base::mapply(FUN = function(x, y){base::rep(x = y, base::length(x = x))}, x = x, y = y), recursive = TRUE, use.names = TRUE)
## 8 mapply(x = x, y = y,FUN = function(x, y){base::rep(x = y, base::length(x = x))}, MoreArgs = NULL, SIMPLIFY = TRUE, USE.NAMES = TRUE)
## 9 GOOD
## 10 GOOD
## 11 do.call(what = base::c, args = code_for_col, quote = FALSE, envir = parent.frame())
## 12 GOOD
## 13 parent.frame(n = 1)