[R] Do you keep an archive of "useful" R code? and if so - how?

Joe King jp at joepking.com
Sun Nov 22 20:32:11 CET 2009


I accidentally sent this directly to the author and didn't reply to the
whole list, I am sorry, I need to remember to hit reply all instead of reply
to the R help list, heres my message:

I keep a separate R file of code I commonly use but more generic. So if I am
making contingency tables I say:

ftable(category, category[top])

or if I am wanting to subset data:

subset2$X5<-recode(subset2$X5, "6:10=1:5")

things like that, generic code that I can refer to and include my variables
in as necessary (as you can tell the "top" mark I made in ftable isn't in
the code but reminds me how the table structures itself. Since I am a newbie
at R I am still keeping notes, I do this for importing things, also
graphics:

xyplot(value~X1,data=subset1,groups=factor(X2),
     type=c("b","g"),ylim=c(0,1),xlim=c(1,5),lwd=1,cex = 1,
     plot.points = TRUE,auto.key = list(points = TRUE,lines = TRUE, space =
"inside"),
     label.curves=FALSE,xlab = "x axis title", ylab = " y axis title ")

so it just lets me organize my codes on my local system. R wiki is ok, but
will be much better as people expand it, I am sure very soon it will grow
exponentially as a good resource. 

(as you can tell some of the code I save includes old variable names instead
of neutral ones, but easy enough to change).

Joe King
206-913-2912
jp at joepking.com
"Never throughout history has a man who lived a life of ease left a name
worth remembering." --Theodore Roosevelt


-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
Behalf Of Tal Galili
Sent: Sunday, November 22, 2009 10:31 AM
To: Marc Schwartz
Cc: r-help at r-project.org; Barry Rowlingson; Jeff.Laake at noaa.gov
Subject: Re: [R] Do you keep an archive of "useful" R code? and if so - how?

Marc and Barry, many thanks for your detailed answers.

Marc -
I thank you for the links and ideas. Thanks to your advice I will look more
into SVN in the future, although it sounds on the surface to require some
learning curve, so It could take me some time to start using it.

Barry -
I am actually a blog builder in my side profession, I already built myself a
blog called:
r-statistics.com
On which I intend to put up good code I will come across.  The problem with
it though is that I don't see blogs as a good information management system.
Since on a blog one is open to the public and doesn't want to leave half
scribles of thoughts (which IS what ends up happening when managing snippets
of code).  Also, blogging is not build for easy hierarchical ordering.

The idea of a wiki is more appealing.
BTW - another suggestion I got was using MS onenote. Although it is not open
source (which is my preference as well), I understood it offers a powerful
solution.

I hope more people will share how they manage their snippets of code.


Best to all of you,
Tal




----------------Contact
Details:-------------------------------------------------------
Contact me: Tal.Galili at gmail.com |  972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
www.r-statistics.com/ (English)
----------------------------------------------------------------------------
------------------




On Sun, Nov 22, 2009 at 8:09 PM, Marc Schwartz <marc_schwartz at me.com> wrote:

> Tal,
>
> I would still use Subversion.
>
> Think of Subversion as as an electronic filing system. You can organize
> code into project trees, with sub-folders and so forth.
>
> As you come across code snippets that you want to save, copy them to a
file
> and commit the file to a project tree or sub-folder, based upon the domain
> of functionality. Add related code snippets to the same domains. That way,
> you have related code snippets in a common area, making recall easier.
>
> The advantage of using a VCS is that you can make trackable modifications
> to the code over time, as your functional requirements change or as you
> discover bugs, etc. to existing code.
>
> In terms of a GUI, for Windows, it seems that most use Tortoise SVN:
>
>   http://tortoisesvn.net/
>
> There are cross-platform GUIs such as RapidSVN (
> http://rapidsvn.tigris.org/), but it all depends upon personal
> preferences. More links here:
>
>   http://subversion.tigris.org/links.html#all-clients
>
> There are also Subversion extensions for editors, such as Emacs, like
> psvn.el (http://www.xsteve.at/prg/vc_svn/) which enable a blending of
> functionality into environments that you may already be using, such as
ESS.
>
> Last but not least, there are also commercial variants of Subversion
> clients, which of course have a cost associated with them. These are also
> listed on the clients link above.
>
> An alternative would be to create a local wiki, the implementation
details,
> as with a Subversion repo, would be dependent upon whether or not you are
> the only person that needs access or if access and/or content modification
> are to be shared.
>
> HTH,
>
> Marc
>
> On Nov 22, 2009, at 11:45 AM, Tal Galili wrote:
>
> Hello Marc and Jeff,
> Thank you for replying.
>
> I am using winXP, and any recommendation for GUI based system will be
> welcomed.
>
> However, my initial question was not how to maintain code that I write
> and develop, but rather how to keep a "filing system" for other peoples
code
> that I find useful.
> Here are some simple examples:
>
>    - A code to allow me to start a window with "history" recording turned
>    on.
>    - A code to have wider margins so to allow more space for the plot
>    labels.
>    - A code for creating an ellipse plot of a matrix of correlations.
>
> All of these example are things I wouldn't put into a Subversion system or
> a new package.
>
> I hope my question was made more clear, and your answer will be much
> appreciated.
>
> Best,
> Tal
>
>
> On Sun, Nov 22, 2009 at 7:13 PM, Marc Schwartz
<marc_schwartz at me.com>wrote:
>
>> On Nov 22, 2009, at 10:53 AM, Tal Galili wrote:
>>
>>  Hello all,
>>>
>>> When using R for some time, one comes across more and more useful
>>> functions.
>>> But naturally we can't remember all of them, so I imagine some of you
>>> save
>>> these snippets of code.
>>> My question to you is how do you manage that code?
>>> Do you use special software, or archiving system?
>>>
>>> Any advice is welcomed.
>>>
>>> Tal
>>>
>>
>>
>> One word:  Subversion (http://subversion.tigris.org/)
>>
>> A version control system is a critical part of any code management
>> process.
>>
>> If you or other users may not be comfortable at the command line using
it,
>> there are a plethora of GUI based clients for Subversion available
depending
>> upon the operating systems you are using.
>>
>> HTH,
>>
>> Marc Schwartz
>>
>>
>
>

	[[alternative HTML version deleted]]

______________________________________________
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