Reputation: 13443
Given a function, how to save it to an R script (.R)?
Save works well with data, but apparently can not create .R data.
Copy pasting from the console to a new script file appears to introduce characters that cause errors.
Upvotes: 5
Views: 5630
Reputation: 21502
I have to ask: why are you writing your functions in the console in the first place? Any number of editors support a "source" call, so you can update the function as you edit. Copy/pasting from the console will carry prompt characters along , if nothing else, so it's a bad idea to begin with.
Upvotes: 3
Reputation: 58825
Take a look at the dump
function. That writes files that are R
code that can be read back in with source
or used in some other way.
Upvotes: 8