write.function: Write the code of a function to a file

View source: R/all.R

write.functionR Documentation

Write the code of a function to a file

Description

Write the code of a function to a file

Usage

write.function(f, file, name = NULL)

Arguments

f

the function

file

where to save it

name

what name to give the object in the file

Value

Invisibly returns the contents of the file that was written. The file is a sourceable file. You can use name to give the object a new name in the file so if you source it, you will not have conflicts.

Examples

my_func <- function(a, b) {a - b * 2 + a^2}
temp_R <- tempfile(fileext = '.R')
kode <- write.function(my_func, file = temp_R)
print(kode)

kode <- write.function(my_func, file = temp_R, name = "diff_name")
print(kode)

print(readLines(temp_R))


adamleerich/alrtools documentation built on March 12, 2024, 11:38 p.m.