saving an R script

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

saving an R script

David Winters
Greetings,

This is a super embarrassing question. But, how do you save an R
script with code? that is, not doing it the cheat way? where you just
hit the "save" button? what function would it be?

I know how to save the environment in code:

save.image(file='myEnvironment.RData')
quit(save='no')
load('myEnvironment.RData')

But how would I do the same thing with a script? rather than the environment?

David

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: saving an R script

Doran, Harold
David

Most of us use an editor of some kind to write our code. I use Notepad++ but there are many options. In this way, you simply write your code in a text file and save it.

Some editors allow for you to execute your code from the script.

-----Original Message-----
From: R-help <[hidden email]> On Behalf Of David Winters
Sent: Thursday, May 09, 2019 10:54 PM
To: [hidden email]
Subject: [R] saving an R script

Greetings,

This is a super embarrassing question. But, how do you save an R script with code? that is, not doing it the cheat way? where you just hit the "save" button? what function would it be?

I know how to save the environment in code:

save.image(file='myEnvironment.RData')
quit(save='no')
load('myEnvironment.RData')

But how would I do the same thing with a script? rather than the environment?

David

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: saving an R script

Jeff Newmiller
In reply to this post by David Winters
Don't. Not from within R.

Edit your script in a text editor, and save it using the usual method for that editor. You can copy lines from that file and paste them into the R console to confirm that each part of your script works, or save it regularly and use the source function from within the R console to have R run the whole thing.

One reason why Integrated Development Environments (IDEs) like RStudio and ESS are so popular is that they turn these steps into a hot-key keyboard combination accessible from the text editor. (They also tend to provide typing completion help that helps you enter syntactically correct code more quickly, and display variable contents in a side bar.) But this is the R-help mailing list, where the topic is the language, not the tools, and you should not assume here that anyone else is using the same editor/IDE that you are.


On May 9, 2019 7:54:10 PM PDT, David Winters <[hidden email]> wrote:

>Greetings,
>
>This is a super embarrassing question. But, how do you save an R
>script with code? that is, not doing it the cheat way? where you just
>hit the "save" button? what function would it be?
>
>I know how to save the environment in code:
>
>save.image(file='myEnvironment.RData')
>quit(save='no')
>load('myEnvironment.RData')
>
>But how would I do the same thing with a script? rather than the
>environment?
>
>David
>
>______________________________________________
>[hidden email] mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.

--
Sent from my phone. Please excuse my brevity.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: saving an R script

Robert Baer
In reply to this post by Doran, Harold
I agree that an editor or a development environment like RStudio is the
best answer, but perhaps savehistory() function is what you are looking for.

On 5/10/2019 8:32 AM, Doran, Harold wrote:

> David
>
> Most of us use an editor of some kind to write our code. I use Notepad++ but there are many options. In this way, you simply write your code in a text file and save it.
>
> Some editors allow for you to execute your code from the script.
>
> -----Original Message-----
> From: R-help <[hidden email]> On Behalf Of David Winters
> Sent: Thursday, May 09, 2019 10:54 PM
> To: [hidden email]
> Subject: [R] saving an R script
>
> Greetings,
>
> This is a super embarrassing question. But, how do you save an R script with code? that is, not doing it the cheat way? where you just hit the "save" button? what function would it be?
>
> I know how to save the environment in code:
>
> save.image(file='myEnvironment.RData')
> quit(save='no')
> load('myEnvironment.RData')
>
> But how would I do the same thing with a script? rather than the environment?
>
> David
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

--


--
Robert W. Baer, Ph.D.
Professor of Physiology
Kirksville College of Osteopathic Medicine
A T Still University of Health Sciences
800 W. Jefferson St
Kirksville, MO 63501
660-626-2321 Department
660-626-2965 FAX

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: saving an R script

Boris Steipe
If the script is originally in a file. I use ...

myScript <- readLines(<filename>)
# [...] modify the myScript vector
writeLines(myScript, con = <filename>)

If this is not what you mean, perhaps you can describe your intended workflow more explicitly.

Cheers,
B.




> On 2019-05-10, at 09:42, Robert Baer <[hidden email]> wrote:
>
> I agree that an editor or a development environment like RStudio is the best answer, but perhaps savehistory() function is what you are looking for.
>
> On 5/10/2019 8:32 AM, Doran, Harold wrote:
>> David
>>
>> Most of us use an editor of some kind to write our code. I use Notepad++ but there are many options. In this way, you simply write your code in a text file and save it.
>>
>> Some editors allow for you to execute your code from the script.
>>
>> -----Original Message-----
>> From: R-help <[hidden email]> On Behalf Of David Winters
>> Sent: Thursday, May 09, 2019 10:54 PM
>> To: [hidden email]
>> Subject: [R] saving an R script
>>
>> Greetings,
>>
>> This is a super embarrassing question. But, how do you save an R script with code? that is, not doing it the cheat way? where you just hit the "save" button? what function would it be?
>>
>> I know how to save the environment in code:
>>
>> save.image(file='myEnvironment.RData')
>> quit(save='no')
>> load('myEnvironment.RData')
>>
>> But how would I do the same thing with a script? rather than the environment?
>>
>> David
>>
>> ______________________________________________
>> [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>> ______________________________________________
>> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
> --
>
>
> --
> Robert W. Baer, Ph.D.
> Professor of Physiology
> Kirksville College of Osteopathic Medicine
> A T Still University of Health Sciences
> 800 W. Jefferson St
> Kirksville, MO 63501
> 660-626-2321 Department
> 660-626-2965 FAX
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: saving an R script

Göran Broström-3
In reply to this post by David Winters
?dump

Den 2019-05-10 kl. 04:54, skrev David Winters:

> Greetings,
>
> This is a super embarrassing question. But, how do you save an R
> script with code? that is, not doing it the cheat way? where you just
> hit the "save" button? what function would it be?
>
> I know how to save the environment in code:
>
> save.image(file='myEnvironment.RData')
> quit(save='no')
> load('myEnvironment.RData')
>
> But how would I do the same thing with a script? rather than the environment?
>
> David
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.