write_function | R Documentation |
Write the code of a function to a file
write_function(f, file, name = NULL)
f |
the function |
file |
where to save it |
name |
what name to give the object in the file |
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.
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))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.