Create an argument function

createArgFunction(
  functionName,
  excludeArgs = c(),
  includeArgs = NULL,
  addArgs = list(),
  rCode = c(),
  newName
)

Arguments

functionName

The name of the function for which we want to create an args function.

excludeArgs

Exclude these arguments from appearing in the args function.

includeArgs

Include these arguments in the args function.

addArgs

Add these arguments to the args functions. Defined as a list with format name = default.

rCode

A character vector representing the R code where the new function should be appended to.

newName

The name of the new function. If not specified, the new name will be automatically derived from the old name.

Value

A character vector with the R code including the new function.

Details

This function can be used to create a function that has (almost) the same interface as the specified function, and the output of this function will be a list of argument values.

Examples

createArgFunction("read.csv", addArgs = list(exposureId = "exposureId"))
#>  [1] "#' Create a parameter object for the function read.csv"                                                                                                                                                                                                                                  
#>  [2] "#'"                                                                                                                                                                                                                                                                                      
#>  [3] "#' @details"                                                                                                                                                                                                                                                                             
#>  [4] "#' Create an object defining the parameter values."                                                                                                                                                                                                                                      
#>  [5] "#'"                                                                                                                                                                                                                                                                                      
#>  [6] "#' @param file NA"                                                                                                                                                                                                                                                                       
#>  [7] "#' @param header  a logical value indicating whether the file contains the names of the variables as its first line.  If missing, the value is determined from the file format: header is set to TRUE if and only if the first row contains one fewer field than the number of columns. "
#>  [8] "#' @param sep NA"                                                                                                                                                                                                                                                                        
#>  [9] "#' @param quote  the set of quoting characters. To disable quoting altogether, use quote = \"\".  See scan for the behaviour on quotes embedded in quotes.  Quoting is only considered for columns read as character, which is all of them unless colClasses is specified. "             
#> [10] "#' @param dec  the character used in the file for decimal points. "                                                                                                                                                                                                                      
#> [11] "#' @param fill NA"                                                                                                                                                                                                                                                                       
#> [12] "#' @param comment.char  character: a character vector of length one containing a single character or an empty string.  Use \"\" to turn off the interpretation of comments altogether. "                                                                                                 
#> [13] "#' @param ...  Further arguments to be passed to read.table. "                                                                                                                                                                                                                           
#> [14] "#' @param exposureId "                                                                                                                                                                                                                                                                   
#> [15] "#'"                                                                                                                                                                                                                                                                                      
#> [16] "#' @export"                                                                                                                                                                                                                                                                              
#> [17] "createRead.csvArgs <- function(file,"                                                                                                                                                                                                                                                    
#> [18] "                               header = TRUE,"                                                                                                                                                                                                                                           
#> [19] "                               sep = \",\","                                                                                                                                                                                                                                             
#> [20] "                               quote = \"\"\","                                                                                                                                                                                                                                          
#> [21] "                               dec = \".\","                                                                                                                                                                                                                                             
#> [22] "                               fill = TRUE,"                                                                                                                                                                                                                                             
#> [23] "                               comment.char = \"\","                                                                                                                                                                                                                                     
#> [24] "                               ...,"                                                                                                                                                                                                                                                     
#> [25] "                               exposureId = \"exposureId\") {"                                                                                                                                                                                                                           
#> [26] "  analysis <- list()"                                                                                                                                                                                                                                                                    
#> [27] "  for (name in names(formals(createRead.csvArgs))) {"                                                                                                                                                                                                                                    
#> [28] "    analysis[[name]] <- get(name)"                                                                                                                                                                                                                                                       
#> [29] "  }"                                                                                                                                                                                                                                                                                     
#> [30] "  class(analysis) <- \"args\""                                                                                                                                                                                                                                                           
#> [31] "  return(analysis)"                                                                                                                                                                                                                                                                      
#> [32] "}"