Re: [R] Saving/loading custom R scripts

2010-09-13 Thread DrCJones

I'm still relatively new to R, so I tried the first of you two solutions: 

.First - function(){
 source(Friedman-Test-with-Post-Hoc.r.txt)
} 

Thanks very much for that, it works perfectly

Cheers
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Saving-loading-custom-R-scripts-tp2530924p2537547.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] Saving/loading custom R scripts

2010-09-09 Thread Bos, Roger
Josh,

I liked your idea of setting the repo in the .Rprofile file, so I tried it:

r - getOption(repos)
r[CRAN] - http://cran.stat.ucla.edu;
options(repos = r)
rm(r)

And now when I open R I get an error:

  Error in r[CRAN] - http://cran.stat.ucla.edu; : 
  cannot do complex assignments in base namespace
 

I am using R2.11.1pat in windows.  

Thanks,

Roger



-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Joshua Wiley
Sent: Wednesday, September 08, 2010 11:20 AM
To: DrCJones
Cc: r-help@r-project.org
Subject: Re: [R] Saving/loading custom R scripts

Hi,

Just create a file called .Rprofile that is located in your working directory 
(this means you could actually have different ones in each working directory).  
In that file, you can put in code just like any other code that would be 
source()d in.  For instance, all my .Rprofile files start with:

r - getOption(repos)
r[CRAN] - http://cran.stat.ucla.edu;
options(repos = r)
rm(r)

So that I do not have to pick my CRAN mirror.  Similarly you could merely add 
this line to the file:

source(file = 
http://www.r-statistics.com/wp-content/uploads/2010/02/Friedman-Test-with-Post-Hoc.r.txt;)

and R would go online, download that file and source it in (not that I am 
recommending re-downloading every time you start R).  Then whatever names they 
used to define the functions, would be in your workspace.

Note that in general, you will not get any output alerting you that it has 
worked; however, if you type ls() you should see those functions'
names.

Cheers,

Josh

On Wed, Sep 8, 2010 at 12:25 AM, DrCJones matthias.godd...@gmail.com wrote:

 Hi,
 How does R automatically load functions so that they are available 
 from the workspace? Is it anything like Matlab - you just specify a 
 directory path and it finds it?

 The reason I ask is because  I found a really nice script that I would 
 like to use on a regular basis, and it would be nice not to have to 
 'copy and paste' it into R on every startup:

 http://www.r-statistics.com/wp-content/uploads/2010/02/Friedman-Test-w
 ith-Post-Hoc.r.txt

 This would be for Ubuntu, if that makes any difference.

 Cheers
 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Saving-loading-custom-R-scripts-tp253092
 4p2530924.html Sent from the R help mailing list archive at 
 Nabble.com.

 __
 R-help@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.




--
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/

__
R-help@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.
***

This message is for the named person's use only. It may\...{{dropped:20}}

__
R-help@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.


Re: [R] Saving/loading custom R scripts

2010-09-09 Thread Joshua Wiley
On Thu, Sep 9, 2010 at 7:05 AM, Bos, Roger roger@rothschild.com wrote:
 Josh,

 I liked your idea of setting the repo in the .Rprofile file, so I tried it:

 r - getOption(repos)
 r[CRAN] - http://cran.stat.ucla.edu;
 options(repos = r)
 rm(r)

 And now when I open R I get an error:

  Error in r[CRAN] - http://cran.stat.ucla.edu; :
  cannot do complex assignments in base namespace

II have been using that for several months now.  I use a text editor
to create ~/.Rprofile (where ~ represents the path to my working
directory), and add those four lines of code.  I don't know why it
would not work for you, and I cannot replicate the error myself so it
is hard to offer any suggestions.



 I am using R2.11.1pat in windows.

 Thanks,

 Roger



 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
 Behalf Of Joshua Wiley
 Sent: Wednesday, September 08, 2010 11:20 AM
 To: DrCJones
 Cc: r-help@r-project.org
 Subject: Re: [R] Saving/loading custom R scripts

 Hi,

 Just create a file called .Rprofile that is located in your working directory 
 (this means you could actually have different ones in each working 
 directory).  In that file, you can put in code just like any other code that 
 would be source()d in.  For instance, all my .Rprofile files start with:

 r - getOption(repos)
 r[CRAN] - http://cran.stat.ucla.edu;
 options(repos = r)
 rm(r)

 So that I do not have to pick my CRAN mirror.  Similarly you could merely add 
 this line to the file:

 source(file = 
 http://www.r-statistics.com/wp-content/uploads/2010/02/Friedman-Test-with-Post-Hoc.r.txt;)

 and R would go online, download that file and source it in (not that I am 
 recommending re-downloading every time you start R).  Then whatever names 
 they used to define the functions, would be in your workspace.

 Note that in general, you will not get any output alerting you that it has 
 worked; however, if you type ls() you should see those functions'
 names.

 Cheers,

 Josh

 On Wed, Sep 8, 2010 at 12:25 AM, DrCJones matthias.godd...@gmail.com wrote:

 Hi,
 How does R automatically load functions so that they are available
 from the workspace? Is it anything like Matlab - you just specify a
 directory path and it finds it?

 The reason I ask is because  I found a really nice script that I would
 like to use on a regular basis, and it would be nice not to have to
 'copy and paste' it into R on every startup:

 http://www.r-statistics.com/wp-content/uploads/2010/02/Friedman-Test-w
 ith-Post-Hoc.r.txt

 This would be for Ubuntu, if that makes any difference.

 Cheers
 --
 View this message in context:
 http://r.789695.n4.nabble.com/Saving-loading-custom-R-scripts-tp253092
 4p2530924.html Sent from the R help mailing list archive at
 Nabble.com.

 __
 R-help@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.




 --
 Joshua Wiley
 Ph.D. Student, Health Psychology
 University of California, Los Angeles
 http://www.joshuawiley.com/

 __
 R-help@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.
 ***

 This message is for the named person's use only. It may
 contain confidential, proprietary or legally privileged
 information. No right to confidential or privileged treatment
 of this message is waived or lost by an error in transmission.
 If you have received this message in error, please immediately
 notify the the sender by e-mail, delete the message and all
 copies from your system and destroy any hard copies.  You must
 not, directly or indirectly, use, disclose, distribute,
 print or copy any part of this message if you are not
 the intended recipient.

 



 __
 This email has been scanned by the MessageLabs Email Security System.
 For more information please visit http://www.messagelabs.com/email
 __




-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/

__
R-help@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.


Re: [R] Saving/loading custom R scripts

2010-09-09 Thread Jakson A. Aquino
On Thu, Sep 9, 2010 at 1:14 PM, Joshua Wiley jwiley.ps...@gmail.com wrote:
 On Thu, Sep 9, 2010 at 7:05 AM, Bos, Roger roger@rothschild.com wrote:
 Josh,

 I liked your idea of setting the repo in the .Rprofile file, so I tried it:

 r - getOption(repos)
 r[CRAN] - http://cran.stat.ucla.edu;
 options(repos = r)
 rm(r)

I couldn't understand why to use 4 lines of code... You could try this:

options(repos = http://cran.stat.ucla.edu;)

__
R-help@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.


Re: [R] Saving/loading custom R scripts

2010-09-09 Thread Joshua Wiley
On Thu, Sep 9, 2010 at 9:28 AM, Jakson A. Aquino jaksonaqu...@gmail.com wrote:
 On Thu, Sep 9, 2010 at 1:14 PM, Joshua Wiley jwiley.ps...@gmail.com wrote:
 On Thu, Sep 9, 2010 at 7:05 AM, Bos, Roger roger@rothschild.com wrote:
 Josh,

 I liked your idea of setting the repo in the .Rprofile file, so I tried it:

 r - getOption(repos)
 r[CRAN] - http://cran.stat.ucla.edu;
 options(repos = r)
 rm(r)

 I couldn't understand why to use 4 lines of code... You could try this:

You can have more than one repository, using repos = url, will
overwrite all of them.  For instance, I believe it is standard on
Windows to have CRAN and CRANextra.  The one line option probably
would be fine often.  In any case, reading through the documentation,
the code used there is:

local({r -
  getOption(repos); r[CRAN] - http://my.local.cran;;
  options(repos=r)})

perhaps wrapping it in local() will take care of your problem, Roger.


 options(repos = http://cran.stat.ucla.edu;)


__
R-help@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.


Re: [R] Saving/loading custom R scripts

2010-09-08 Thread Abhijit Dasgupta, PhD
 You can create a .First function in your .Rprofile file (which  will 
be in ~/.Rprofile). For example


.First - function(){
source(Friedman-Test-with-Post-Hoc.r.txt)
}

You can also create your own package (mylibrary) down the line (see 
the R manual for creating extensions at 
http://cran.fhcrc.org/doc/manuals/R-exts.pdf) which will be a collection 
of your custom scripts that you have written, and then you can 
automatically load them using


.First - function(){
library(mylibrary)
}

Hope this helps.

Abhijit

On 9/8/10 3:25 AM, DrCJones wrote:

Hi,
How does R automatically load functions so that they are available from the
workspace? Is it anything like Matlab - you just specify a directory path
and it finds it?

The reason I ask is because  I found a really nice script that I would like
to use on a regular basis, and it would be nice not to have to 'copy and
paste' it into R on every startup:

http://www.r-statistics.com/wp-content/uploads/2010/02/Friedman-Test-with-Post-Hoc.r.txt

This would be for Ubuntu, if that makes any difference.

Cheers



--

Abhijit Dasgupta, PhD
Director and Principal Statistician
ARAASTAT
Ph: 301.385.3067
E: adasgu...@araastat.com
W: http://www.araastat.com

__
R-help@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.


Re: [R] Saving/loading custom R scripts

2010-09-08 Thread Joshua Wiley
Hi,

Just create a file called .Rprofile that is located in your working
directory (this means you could actually have different ones in each
working directory).  In that file, you can put in code just like any
other code that would be source()d in.  For instance, all my .Rprofile
files start with:

r - getOption(repos)
r[CRAN] - http://cran.stat.ucla.edu;
options(repos = r)
rm(r)

So that I do not have to pick my CRAN mirror.  Similarly you could
merely add this line to the file:

source(file = 
http://www.r-statistics.com/wp-content/uploads/2010/02/Friedman-Test-with-Post-Hoc.r.txt;)

and R would go online, download that file and source it in (not that I
am recommending re-downloading every time you start R).  Then whatever
names they used to define the functions, would be in your workspace.

Note that in general, you will not get any output alerting you that it
has worked; however, if you type ls() you should see those functions'
names.

Cheers,

Josh

On Wed, Sep 8, 2010 at 12:25 AM, DrCJones matthias.godd...@gmail.com wrote:

 Hi,
 How does R automatically load functions so that they are available from the
 workspace? Is it anything like Matlab - you just specify a directory path
 and it finds it?

 The reason I ask is because  I found a really nice script that I would like
 to use on a regular basis, and it would be nice not to have to 'copy and
 paste' it into R on every startup:

 http://www.r-statistics.com/wp-content/uploads/2010/02/Friedman-Test-with-Post-Hoc.r.txt

 This would be for Ubuntu, if that makes any difference.

 Cheers
 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Saving-loading-custom-R-scripts-tp2530924p2530924.html
 Sent from the R help mailing list archive at Nabble.com.

 __
 R-help@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.




-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/

__
R-help@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.


Re: [R] Saving/loading custom R scripts

2010-09-08 Thread Bert Gunter
.. Not quite.

?Startup

provides details, but note the comment about only the base package
being loaded and the need to use somepackage::somefunction() or to
explicitly first load a package whose functions are used in .Profile.

Note also that .First could also be used instead of putting the code
in a profile file.

Cheers,

Bert Gunter
Genentech Nonclinical Statistics

On Wed, Sep 8, 2010 at 8:20 AM, Joshua Wiley jwiley.ps...@gmail.com wrote:
 Hi,

 Just create a file called .Rprofile that is located in your working
 directory (this means you could actually have different ones in each
 working directory).  In that file, you can put in code just like any
 other code that would be source()d in.  For instance, all my .Rprofile
 files start with:

 r - getOption(repos)
 r[CRAN] - http://cran.stat.ucla.edu;
 options(repos = r)
 rm(r)

 So that I do not have to pick my CRAN mirror.  Similarly you could
 merely add this line to the file:

 source(file = 
 http://www.r-statistics.com/wp-content/uploads/2010/02/Friedman-Test-with-Post-Hoc.r.txt;)

 and R would go online, download that file and source it in (not that I
 am recommending re-downloading every time you start R).  Then whatever
 names they used to define the functions, would be in your workspace.

 Note that in general, you will not get any output alerting you that it
 has worked; however, if you type ls() you should see those functions'
 names.

 Cheers,

 Josh

 On Wed, Sep 8, 2010 at 12:25 AM, DrCJones matthias.godd...@gmail.com wrote:

 Hi,
 How does R automatically load functions so that they are available from the
 workspace? Is it anything like Matlab - you just specify a directory path
 and it finds it?

 The reason I ask is because  I found a really nice script that I would like
 to use on a regular basis, and it would be nice not to have to 'copy and
 paste' it into R on every startup:

 http://www.r-statistics.com/wp-content/uploads/2010/02/Friedman-Test-with-Post-Hoc.r.txt

 This would be for Ubuntu, if that makes any difference.

 Cheers
 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Saving-loading-custom-R-scripts-tp2530924p2530924.html
 Sent from the R help mailing list archive at Nabble.com.

 __
 R-help@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.




 --
 Joshua Wiley
 Ph.D. Student, Health Psychology
 University of California, Los Angeles
 http://www.joshuawiley.com/

 __
 R-help@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.




-- 
Bert Gunter
Genentech Nonclinical Biostatistics
467-7374
http://devo.gene.com/groups/devo/depts/ncb/home.shtml

__
R-help@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.


Re: [R] Saving/loading custom R scripts

2010-09-08 Thread Peter Ehlers

One comment on the function: I see that it uses T/F instead of
TRUE/FALSE in a number of places. You'll save yourself some
headaches if you replace those 'T/F's.

  -Peter Ehlers

On 2010-09-08 1:25, DrCJones wrote:


Hi,
How does R automatically load functions so that they are available from the
workspace? Is it anything like Matlab - you just specify a directory path
and it finds it?

The reason I ask is because  I found a really nice script that I would like
to use on a regular basis, and it would be nice not to have to 'copy and
paste' it into R on every startup:

http://www.r-statistics.com/wp-content/uploads/2010/02/Friedman-Test-with-Post-Hoc.r.txt

This would be for Ubuntu, if that makes any difference.

Cheers


__
R-help@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.