Etienne Low-Décarie
Etienne Low-Décarie

Reputation: 13443

How to save a function as new R script?

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

Answers (2)

Carl Witthoft
Carl Witthoft

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

Brian Diggs
Brian Diggs

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

Related Questions