Hi there, Often times, I would run R in the terminal when the task is computationally intensive and a nice-looking UI is less desired. However, pasting a large chunk of code into the terminal often times ends up being messed up. In Python, the same problem would happen, however, iPython provides a small functionality called magic word such as %paste that can help paste the code neatly into the terminal. I'm wondering if there's a similar functionality in R. Thanks, -- *Xu Tian* [[alternative HTML version deleted]]
> On Oct 29, 2015, at 10:16 AM, Victor Tian <tianxu03 at gmail.com> wrote: > > Hi there, > > Often times, I would run R in the terminal when the task is computationally > intensive and a nice-looking UI is less desired. > > However, pasting a large chunk of code into the terminal often times ends > up being messed up. In Python, the same problem would happen, however, > iPython provides a small functionality called magic word such as %paste > that can help paste the code neatly into the terminal. > > I'm wondering if there's a similar functionality in R. > > Thanks, > > -- > *Xu Tian*Rather than pasting a large amount of code into the terminal, put the code into a text file (e.g. MyCode.R) and use ?source i your terminal session, to read in the file to then be parsed and run. Regards, Marc Schwartz
I highly recommend ?source. You can use source("clipboard") on windows, but creating complete files that define functions and feeding those complete files to source is a significant step in developing reproducible analyses. Whenever you find yourself pasting more than a couple of lines (one or two function calls) you should be making another function. However, even if you resist making functions you should be making a habit of sourcing complete files from disk rather than passing large chunks of code. --------------------------------------------------------------------------- Jeff Newmiller The ..... ..... Go Live... DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/Batteries O.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --------------------------------------------------------------------------- Sent from my phone. Please excuse my brevity. On October 29, 2015 8:16:17 AM MST, Victor Tian <tianxu03 at gmail.com> wrote:>Hi there, > >Often times, I would run R in the terminal when the task is >computationally >intensive and a nice-looking UI is less desired. > >However, pasting a large chunk of code into the terminal often times >ends >up being messed up. In Python, the same problem would happen, however, >iPython provides a small functionality called magic word such as %paste >that can help paste the code neatly into the terminal. > >I'm wondering if there's a similar functionality in R. > >Thanks,
> On Oct 29, 2015, at 10:43 AM, Marc Schwartz <marc_schwartz at me.com> wrote: > > >> On Oct 29, 2015, at 10:16 AM, Victor Tian <tianxu03 at gmail.com> wrote: >> >> Hi there, >> >> Often times, I would run R in the terminal when the task is computationally >> intensive and a nice-looking UI is less desired. >> >> However, pasting a large chunk of code into the terminal often times ends >> up being messed up. In Python, the same problem would happen, however, >> iPython provides a small functionality called magic word such as %paste >> that can help paste the code neatly into the terminal. >> >> I'm wondering if there's a similar functionality in R. >> >> Thanks, >> >> -- >> *Xu Tian* > > > Rather than pasting a large amount of code into the terminal, put the code into a text file (e.g. MyCode.R) and use ?source i your terminal session, to read in the file to then be parsed and run. >BTW, another alternative is to run 'R CMD BATCH MyCode.R' from the CLI (Linux and OS X). If you are on Windows, I believe that would be: R.exe CMD BATCH MyCode.R possibly having to specify the $PATH to R.exe. See ?BATCH for additional information and Appendix B in An Introduction to R: https://cran.r-project.org/doc/manuals/r-release/R-intro.html#Invoking-R Regards, Marc
Thanks, Marc and Jeff, for the advice of running a file of R code rather than a chunk of R code. Just thought it would be nice to have a feature like this so that there's still a sense of interaction in running R code. It was a random idea and I think using "source" would achieve the same goal. Thanks, Xu On Thu, Oct 29, 2015 at 11:51 AM, Jeff Newmiller <jdnewmil at dcn.davis.ca.us> wrote:> I highly recommend ?source. > > You can use source("clipboard") on windows, but creating complete files > that define functions and feeding those complete files to source is a > significant step in developing reproducible analyses. Whenever you find > yourself pasting more than a couple of lines (one or two function calls) > you should be making another function. However, even if you resist making > functions you should be making a habit of sourcing complete files from disk > rather than passing large chunks of code. > --------------------------------------------------------------------------- > Jeff Newmiller The ..... ..... Go Live... > DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live > Go... > Live: OO#.. Dead: OO#.. Playing > Research Engineer (Solar/Batteries O.O#. #.O#. with > /Software/Embedded Controllers) .OO#. .OO#. rocks...1k > --------------------------------------------------------------------------- > Sent from my phone. Please excuse my brevity. > > On October 29, 2015 8:16:17 AM MST, Victor Tian <tianxu03 at gmail.com> > wrote: > >Hi there, > > > >Often times, I would run R in the terminal when the task is > >computationally > >intensive and a nice-looking UI is less desired. > > > >However, pasting a large chunk of code into the terminal often times > >ends > >up being messed up. In Python, the same problem would happen, however, > >iPython provides a small functionality called magic word such as %paste > >that can help paste the code neatly into the terminal. > > > >I'm wondering if there's a similar functionality in R. > > > >Thanks, > >-- *Xu Tian* [[alternative HTML version deleted]]