[R] "verbose source" command?

Duncan Murdoch murdoch.duncan at gmail.com
Fri Oct 14 11:25:13 CEST 2011


On 11-10-13 10:16 PM, R. Michael Weylandt wrote:
> source(FILE, print.eval = TRUE)

or

source(FILE, echo = TRUE)

which will also echo the inputs - the students will find this helpful.

Duncan Murdoch

>
> Hope this helps&  good work on getting the next round of R enthusiasts
> up and going!
>
> Michael
>
> On Thu, Oct 13, 2011 at 8:59 PM, Stephen Davies<stephen at umw.edu>  wrote:
>> (Apologies for the n00b question.)
>>
>> Hello, I'm teaching R in an introductory programming course and am walking
>> the students through the baby steps. One thing I'd like to be able to do is
>> have them copy the commands they type at the R console into a text file,
>> and then execute the text file to see the results. For instance, if their
>> session looks like this:
>>
>> 3+4
>> [1] 7
>> factorial(10)
>> [1] 3628800
>>
>> I'd like for them to create a text file called "myCommands.R" with contents:
>>
>> 3+4
>> factorial(10)
>>
>> and then run it at the R console using source("myCommands.R"), and see this
>> output:
>>
>> [1] 7
>> [1] 3628800
>>
>> This would help with many things, including my grading their lab work.
>>
>> Unfortunately, if I/they do this using the source() command as it stands,
>> the result is of course no output at all, because nothing is being
>> explicitly printed (with print() or cat() command, for example).
>>
>> My question is: is there a command to do what I'm trying to do here? Is
>> there some kind of "verbose source" command (or mode) that will run a .R
>> script/program/file and print all the results from it exactly as if those
>> commands had been entered at the console?
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> 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.
>>
>
> ______________________________________________
> R-help at r-project.org mailing list
> 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.



More information about the R-help mailing list