Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to save a function as new R script?

Tags:

function

r

save

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.

like image 497
Etienne Low-Décarie Avatar asked Jun 15 '12 17:06

Etienne Low-Décarie


2 Answers

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.

like image 28
Carl Witthoft Avatar answered Oct 18 '22 09:10

Carl Witthoft


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.

like image 60
Brian Diggs Avatar answered Oct 18 '22 09:10

Brian Diggs