How to save a function as a new R script?

For a function, how to save it in an R script (.R)?

Saving works well with data, but apparently cannot create .R data.

Copy paste from the console to a new script file to enter characters that cause errors.

+4
source share
2 answers

Take a look at the dump function. This writes files that are R code, which can be read using source or used in some other way.

+7
source

I have to ask: why are you primarily writing your functions on the console? Any number of editors supports the "original" call, so you can update the function when editing. Copying / pasting from the console will contain inviting characters, if nothing else, so this is a bad idea.

+2
source

All Articles