Retrieve a function's arguments and default values in a list.

FctArgs(name, sort = FALSE)

Arguments

name

name of the function.

sort

logical. Should the function arguments be sorted? Defaults to FALSE.

Value

a data.frame with the default in the first columns and with row.names as argument names.

Author

Andri Signorell <andri@signorell.net>

See also

formalArgs, formals, args, alist, body

Examples

formalArgs(PlotFdist)
#>  [1] "x"               "main"            "xlab"            "xlim"           
#>  [5] "args.hist"       "args.rug"        "args.dens"       "args.curve"     
#>  [9] "args.boxplot"    "args.ecdf"       "args.curve.ecdf" "heights"        
#> [13] "pdist"           "na.rm"           "cex.axis"        "cex.main"       
#> [17] "mar"             "las"            
formals(PlotFdist)
#> $x
#> 
#> 
#> $main
#> deparse(substitute(x))
#> 
#> $xlab
#> [1] ""
#> 
#> $xlim
#> NULL
#> 
#> $args.hist
#> NULL
#> 
#> $args.rug
#> [1] NA
#> 
#> $args.dens
#> NULL
#> 
#> $args.curve
#> [1] NA
#> 
#> $args.boxplot
#> NULL
#> 
#> $args.ecdf
#> NULL
#> 
#> $args.curve.ecdf
#> [1] NA
#> 
#> $heights
#> NULL
#> 
#> $pdist
#> NULL
#> 
#> $na.rm
#> [1] FALSE
#> 
#> $cex.axis
#> NULL
#> 
#> $cex.main
#> NULL
#> 
#> $mar
#> NULL
#> 
#> $las
#> [1] 1
#> 

# compare:
FctArgs(PlotFdist)
#>                 value                 
#> x                                     
#> main            deparse(substitute(x))
#> xlab            ""                    
#> xlim            NULL                  
#> args.hist       NULL                  
#> args.rug        NA                    
#> args.dens       NULL                  
#> args.curve      NA                    
#> args.boxplot    NULL                  
#> args.ecdf       NULL                  
#> args.curve.ecdf NA                    
#> heights         NULL                  
#> pdist           NULL                  
#> na.rm           FALSE                 
#> cex.axis        NULL                  
#> cex.main        NULL                  
#> mar             NULL                  
#> las             1                     

# alternative also spotting unexported functions
GetArgs <- function(FUN) {
  a <- formals(getAnywhere(FUN)$objs[[1]])
  arg.labels <- names(a)
  arg.values <- as.character(a)
  char <- sapply(a, is.character)
  arg.values[char] <- paste("\"", arg.values[char], "\"", sep="")

  c(fname=FUN, 
    args=paste(StrTrim(gsub("= $", "", 
               paste(arg.labels, arg.values, sep=" = "))), 
               collapse=", "))

}

fcts <- grep("plot.Desc", unclass(lsf.str(envir = asNamespace("DescTools"), 
                                          all.names = TRUE)), value=TRUE)
fargs <- t(unname(sapply(fcts, GetArgs)))
fargs
#>       [,1]                 
#>  [1,] "plot.Desc"          
#>  [2,] "plot.Desc.Date"     
#>  [3,] "plot.Desc.character"
#>  [4,] "plot.Desc.default"  
#>  [5,] "plot.Desc.factfact" 
#>  [6,] "plot.Desc.factnum"  
#>  [7,] "plot.Desc.factor"   
#>  [8,] "plot.Desc.integer"  
#>  [9,] "plot.Desc.logical"  
#> [10,] "plot.Desc.matrix"   
#> [11,] "plot.Desc.numeric"  
#> [12,] "plot.Desc.numfact"  
#> [13,] "plot.Desc.numnum"   
#> [14,] "plot.Desc.ordered"  
#> [15,] "plot.Desc.table"    
#> [16,] "plot.Desc.ts"       
#> [17,] "plot.Desc.xtabs"    
#>       [,2]                                                                                                                                                                            
#>  [1,] "x, main = NULL, ..."                                                                                                                                                           
#>  [2,] "x, main = NULL, breaks = NULL, type = c(1, 2, 3), ..."                                                                                                                         
#>  [3,] "x, main = NULL, ..."                                                                                                                                                           
#>  [4,] "x, main = NULL, ..."                                                                                                                                                           
#>  [5,] "x, main = NULL, col1 = NULL, col2 = NULL, horiz = TRUE, ..."                                                                                                                   
#>  [6,] "x, main = NULL, col = NULL, add_ni = TRUE, smooth = NULL, ..."                                                                                                                 
#>  [7,] "x, main = NULL, maxlablen = 25, type = c(\"bar\", \"dot\"), col = NULL, border = NULL, xlim = NULL, ecdf = TRUE, ..."                                                          
#>  [8,] "x, main = NULL, ..."                                                                                                                                                           
#>  [9,] "x, main = NULL, xlab = \"\", col = NULL, legend = TRUE, xlim = c(0, 1), confint = TRUE, ..."                                                                                   
#> [10,] "x, main = NULL, col1 = NULL, col2 = NULL, horiz = TRUE, ..."                                                                                                                   
#> [11,] "x, main = NULL, args.hist = NULL, ..."                                                                                                                                         
#> [12,] "x, main = NULL, add_ni = TRUE, args.boxplot = NULL, col = DescToolsOptions(\"col\"), xlim = NULL, args.legend = NULL, type = c(\"design\", \"dens\"), ..."                     
#> [13,] "x, main = NULL, col = SetAlpha(1, 0.3), pch = NULL, cex = par(\"cex\"), bg = par(\"bg\"), xlab = NULL, ylab = NULL, smooth = NULL, smooth.front = TRUE, conf.level = 0.95, ..."
#> [14,] "x, main = NULL, ..."                                                                                                                                                           
#> [15,] "x, main = NULL, col1 = NULL, col2 = NULL, horiz = TRUE, ..., xlab = NULL, ylab = NULL, which = c(1, 2)"                                                                        
#> [16,] "x, main = NULL, ..."                                                                                                                                                           
#> [17,] "x, main = NULL, col1 = NULL, col2 = NULL, horiz = TRUE, ..."