Learn R Programming

sig (version 0.0-6)

write_sigs: Write sigs to file

Description

Writes a list of function signatures to a file.

Usage

write_sigs(x, file = stdout(), ...)

# S3 method for default write_sigs(x, file = stdout(), ...)

# S3 method for siglist write_sigs(x, file = stdout(), ...)

# S3 method for list write_sigs(x, file = stdout(), ...)

# S3 method for environment write_sigs(x, file = stdout(), ...)

# S3 method for character write_sigs(x, file = stdout(), ...)

Arguments

x

A list of function signatures. See details.

file

A file path or connection to write the output to (stdout by default).

...

passed to toString.siglist.

Value

A character vector of the lines that were written to file is invisibly returned. Mostly invoked for the side effect of writing function signatures to a file.

Details

Where x is an object of class siglist, the function essentially calls writeLines(tostring(x). If the input is a single function signature (of class sig), then it is coerced into a siglist. If the input is an environment or path to a file, then list_sigs is called on the input before writing.

Examples

Run this code
# NOT RUN {
#Step by step:
#First, list some sigs.
utils_sigs <- list_sigs(pkg2env(utils))   
#Without a file argument, sigs are just printed to the console.          
head(write_sigs(utils_sigs))
#Write to a file
tmpf <- tempfile("sig", fileext = ".R")
write_sigs(utils_sigs, tmpf)    
#Open the file we've just written
readLines(tmpf, n = 6)
#Can also list and write in one line.
tmpf2 <- tempfile("sig", fileext = ".R") 
write_sigs(pkg2env(grDevices), tmpf2)
#Single sigs are coerced to siglists
write_sigs(sig(stats::var))  
# }

Run the code above in your browser using DataLab