[R] How to avoid copy-paste when copying code from this list
johannes rara
johannesraja at gmail.com
Sat Sep 19 10:48:45 CEST 2009
The R help mailing list posting guide
http://www.r-project.org/posting-guide.html
suggests to give an example in this form
...snip...
f I have a matrix x as follows:
> x <- matrix(1:8, nrow=4, ncol=2,
dimnames=list(c("A","B","C","D"), c("x","y"))
> x
x y
A 1 5
B 2 6
C 3 7
D 4 8
>
...snip...
Would it be reasonable to consider changing this guide about this matter?
2009/9/19 Ted Harding <Ted.Harding at manchester.ac.uk>:
> On 19-Sep-09 08:00:18, Cedrick W. Johnson wrote:
>> At least in windows, if you right click directly in the r console,
>> there's a command for 'Paste commands only' which may be one
>> solution...
>> Not sure about other platforms..
>>
>> hth
>> c
>
> It was precisely for this kind of reason that, when including
> R code in postings to the list, I took to formatting it in the
> following kind of way:
>
> a <- 1:10
> a
> # [1] 1 2 3 4 5 6 7 8 9 10
>
> a[1:5]
> # [1] 1 2 3 4 5
>
> In this way, any R commands copy-pasted into R will work as-is,
> anything else is a comment and will not interfere. I notice that
> some other people also post their code in this way.
>
> I recommend it to all! If the code has been copy-pasted into the
> email from an R console, then of course the ">" prompts will be
> there. But then I just edit these out of the email. A bit more
> trouble for me, but a lot less trouble for others.
>
> For instance, if someone had posted the above as copied from the
> R console in its original form
>
>> a <- 1:10
>> a
> [1] 1 2 3 4 5 6 7 8 9 10
>
>> a[1:5]
> [1] 1 2 3 4 5
>
> and I wanted to try it out, then I would either have to re-open the
> email in "edit" mode so as to edit the email itself, or else copy-paste
> the above into a text-edit window[*] and pre-edit it there before
> copying into R.
>
> [*] I would be using 'vim' in a Linux xterm. Removal of the "> "
> prompts (or "+ " continuation prompts) from a long series of commands
> is relatively easy: Just higlight a column-block of the first two
> columns, then press "d" to delete them. But you would first need to
> enter " # " for other stuff by hand.
>
> Best wishes to all,
> Ted.
>
>>
>> johannes rara wrote:
>>> Hi,
>>>
>>> How do you people avoid copy-pasting and manual editing of the code
>>> posted in this list? I mean that if some one post a solution for an
>>> answer like this:
>>>
>>>
>>>> a <- 1:10
>>>> a
>>>>
>>> [1] 1 2 3 4 5 6 7 8 9 10
>>>
>>>> a[1:5]
>>>>
>>> [1] 1 2 3 4 5
>>>
>>>
>>> I have to copy-paste it to e.g. Tinn-R and remove "> " part of the
>>> line to try it in my R. When you keep doing this it gets quite
>>> annoying. How do you people avoid this (search and replace, perhaps?).
>>> The best way would be to able to send this straight from your e-mail
>>> reader into R (e.g. from gmail).
>>>
>>> -Johannes
>
> --------------------------------------------------------------------
> E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk>
> Fax-to-email: +44 (0)870 094 0861
> Date: 19-Sep-09 Time: 09:33:48
> ------------------------------ XFMail ------------------------------
>
> ______________________________________________
> 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