[R] How to read stored functions

2007-09-25 Thread Mauricio Malfert
Hi I'm simulating missing data patterns and  I've started to get a lot of
functions in the same .R file is it possible to store al these functions in
a library like one does in C++ (i.e the .h file) and read the functions from
the main .R file

/Mauricio

[[alternative HTML version deleted]]

__
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] How to read stored functions

2007-09-25 Thread Vladimir Eremeev


Mauricio Malfert wrote:
 
 Hi I'm simulating missing data patterns and  I've started to get a lot of
 functions in the same .R file is it possible to store al these functions
 in
 a library like one does in C++ (i.e the .h file) and read the functions
 from
 the main .R file
 /Mauricio
 

You can save your functions to a file with
save(names,file=/path/to/func_lib.RData) 
and then attach(/path/to/func_lib.RData).

Or, you can create a package and load it with library() or require()


-- 
View this message in context: 
http://www.nabble.com/How-to-read-stored-functions-tf4513863.html#a12874535
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] How to read stored functions

2007-09-25 Thread Jared O'Connell
Having your functions in a text file, say functions.r and then calling:

source(functions.r)

is also an option.  This assumes you are in the same directory as 
functions.r.  Perhaps take a look at ?setwd and ?getwd as well.



On 9/25/07, Vladimir Eremeev [EMAIL PROTECTED] wrote:



 Mauricio Malfert wrote:
 
  Hi I'm simulating missing data patterns and  I've started to get a lot
 of
  functions in the same .R file is it possible to store al these functions
  in
  a library like one does in C++ (i.e the .h file) and read the functions
  from
  the main .R file
  /Mauricio
 

 You can save your functions to a file with
 save(names,file=/path/to/func_lib.RData)
 and then attach(/path/to/func_lib.RData).

 Or, you can create a package and load it with library() or require()


 --
 View this message in context:
 http://www.nabble.com/How-to-read-stored-functions-tf4513863.html#a12874535
 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.


[[alternative HTML version deleted]]

__
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] How to read stored functions

2007-09-25 Thread Vladimir Eremeev

source'ing is a bad practice because this saves additional copies of
functions and data in the local workspace.

Wasting disk space is not a problem now since HDDs are cheap and function
bodies are generally small.

But, when you change any function body, you have to repeat that source()
call in local workspace of every project using the functions.


Jared O'Connell wrote:
 
 Having your functions in a text file, say functions.r and then calling:
 
source(functions.r)
 
 is also an option.  This assumes you are in the same directory as 
 functions.r.  Perhaps take a look at ?setwd and ?getwd as well.
 
 
 On 9/25/07, Vladimir Eremeev [EMAIL PROTECTED] wrote:

 You can save your functions to a file with
 save(names,file=/path/to/func_lib.RData)
 and then attach(/path/to/func_lib.RData).

 Or, you can create a package and load it with library() or require()
 
 Mauricio Malfert wrote:
 
  Hi I'm simulating missing data patterns and  I've started to get a lot
  of
  functions in the same .R file is it possible to store al these
 functions
  in
  a library like one does in C++ (i.e the .h file) and read the functions
  from
  the main .R file
  /Mauricio
 

-- 
View this message in context: 
http://www.nabble.com/How-to-read-stored-functions-tf4513863.html#a12875031
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] How to read stored functions

2007-09-25 Thread Jared O'Connell
...and my R education (and embarassment) continues ;)

On 9/25/07, Vladimir Eremeev [EMAIL PROTECTED] wrote:


 source'ing is a bad practice because this saves additional copies of
 functions and data in the local workspace.

 Wasting disk space is not a problem now since HDDs are cheap and function
 bodies are generally small.

 But, when you change any function body, you have to repeat that source()
 call in local workspace of every project using the functions.


 Jared O'Connell wrote:
 
  Having your functions in a text file, say functions.r and then
 calling:
 
 source(functions.r)
 
  is also an option.  This assumes you are in the same directory as 
  functions.r.  Perhaps take a look at ?setwd and ?getwd as well.
 
 
  On 9/25/07, Vladimir Eremeev [EMAIL PROTECTED] wrote:
 
  You can save your functions to a file with
  save(names,file=/path/to/func_lib.RData)
  and then attach(/path/to/func_lib.RData).
 
  Or, you can create a package and load it with library() or require()
 
  Mauricio Malfert wrote:
  
   Hi I'm simulating missing data patterns and  I've started to get a
 lot
   of
   functions in the same .R file is it possible to store al these
  functions
   in
   a library like one does in C++ (i.e the .h file) and read the
 functions
   from
   the main .R file
   /Mauricio
 

 --
 View this message in context:
 http://www.nabble.com/How-to-read-stored-functions-tf4513863.html#a12875031
 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.


[[alternative HTML version deleted]]

__
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] How to read stored functions

2007-09-25 Thread Mark Wardle
Jared:

I agree with your advice - I use source() too!

I think I work in a different way to many, and don't ever save
current workspace but use the interactive R environment cutting and
pasting code from documents held under version control.

As long as one is careful, I don't think there is any problem!

Best wishes,

Mark

On 25/09/2007, Jared O'Connell [EMAIL PROTECTED] wrote:
 ...and my R education (and embarassment) continues ;)

 On 9/25/07, Vladimir Eremeev [EMAIL PROTECTED] wrote:
 
 
  source'ing is a bad practice because this saves additional copies of
  functions and data in the local workspace.
 
  Wasting disk space is not a problem now since HDDs are cheap and function
  bodies are generally small.
 
  But, when you change any function body, you have to repeat that source()
  call in local workspace of every project using the functions.
 
 
  Jared O'Connell wrote:
  
   Having your functions in a text file, say functions.r and then
  calling:
  
  source(functions.r)
  
   is also an option.  This assumes you are in the same directory as 
   functions.r.  Perhaps take a look at ?setwd and ?getwd as well.
  
  
   On 9/25/07, Vladimir Eremeev [EMAIL PROTECTED] wrote:
  
   You can save your functions to a file with
   save(names,file=/path/to/func_lib.RData)
   and then attach(/path/to/func_lib.RData).
  
   Or, you can create a package and load it with library() or require()
  
   Mauricio Malfert wrote:
   
Hi I'm simulating missing data patterns and  I've started to get a
  lot
of
functions in the same .R file is it possible to store al these
   functions
in
a library like one does in C++ (i.e the .h file) and read the
  functions
from
the main .R file
/Mauricio
  
 
  --
  View this message in context:
  http://www.nabble.com/How-to-read-stored-functions-tf4513863.html#a12875031
  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.
 

 [[alternative HTML version deleted]]

 __
 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 email has been scanned by the MessageLabs Email Security System.
 For more information please visit http://www.messagelabs.com/email
 __



-- 
Dr. Mark Wardle
Specialist registrar, Neurology
Cardiff, UK

__
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] How to read stored functions

2007-09-25 Thread Duncan Murdoch
On 9/25/2007 4:15 AM, Vladimir Eremeev wrote:
 source'ing is a bad practice because this saves additional copies of
 functions and data in the local workspace.
 
 Wasting disk space is not a problem now since HDDs are cheap and function
 bodies are generally small.
 
 But, when you change any function body, you have to repeat that source()
 call in local workspace of every project using the functions.

I disagree.  The bad practice is having local workspaces.  It's easy to 
see what's in a text file, and hard to see exactly what's in a .RData 
file, so it's better to keep everything as text.  There are situations 
where the overhead of converting text to internal objects is too high,
e.g. the results of long simulation runs may be worth saving in binary 
form so they're quicker to load.  But you can save objects one (or a 
few) at a time, you don't need to save everything.

If you find you're using a function in multiple projects, then it's time 
to build a small package to hold it.  The first line in the scripts for 
each of those projects can be

library(MyPackage)

If you think building a package is too much overhead, you can replace 
the line above with

source(path/to/MyFunction.R)

but this is less portable, since you may not have the function installed 
in the same directory on every system you use.

Duncan Murdoch

 
 
 Jared O'Connell wrote:
 
 Having your functions in a text file, say functions.r and then calling:
 
source(functions.r)
 
 is also an option.  This assumes you are in the same directory as 
 functions.r.  Perhaps take a look at ?setwd and ?getwd as well.
 
 
 On 9/25/07, Vladimir Eremeev [EMAIL PROTECTED] wrote:

 You can save your functions to a file with
 save(names,file=/path/to/func_lib.RData)
 and then attach(/path/to/func_lib.RData).

 Or, you can create a package and load it with library() or require()
 
 Mauricio Malfert wrote:
 
  Hi I'm simulating missing data patterns and  I've started to get a lot
  of
  functions in the same .R file is it possible to store al these
 functions
  in
  a library like one does in C++ (i.e the .h file) and read the functions
  from
  the main .R file
  /Mauricio
 


__
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] How to read stored functions

2007-09-25 Thread Vladimir Eremeev


Duncan Murdoch-2 wrote:
 
 On 9/25/2007 4:15 AM, Vladimir Eremeev wrote:
 source'ing is a bad practice because this saves additional copies of
 functions and data in the local workspace.
 
 Wasting disk space is not a problem now since HDDs are cheap and function
 bodies are generally small.
 
 But, when you change any function body, you have to repeat that source()
 call in local workspace of every project using the functions.
 
 I disagree.  The bad practice is having local workspaces.  It's easy to 
 see what's in a text file, and hard to see exactly what's in a .RData 
 file, so it's better to keep everything as text.  There are situations 
 where the overhead of converting text to internal objects is too high,
 e.g. the results of long simulation runs may be worth saving in binary 
 form so they're quicker to load.  But you can save objects one (or a 
 few) at a time, you don't need to save everything.
 

It's the matter of taste. I prefer separate directories for separate
projects. Sometimes I have 'subprojects' with their own workspaces. If I
have large objects, I usually don't analyze them with a text viewer.
And, the last. The option of saving the local workspace exists in R for
years. As one of its developers you know that the R Core Team has the very
strong feedback with users. I don't think that bad features exist in such
conditions for such a long time.


Duncan Murdoch-2 wrote:
 
 If you find you're using a function in multiple projects, then it's time 
 to build a small package to hold it.  The first line in the scripts for 
 each of those projects can be
 
 library(MyPackage)
 
 If you think building a package is too much overhead, you can replace 
 the line above with
 
 source(path/to/MyFunction.R)
 
 but this is less portable, since you may not have the function installed 
 in the same directory on every system you use.
 
 Duncan Murdoch
 
 
That's right.
-- 
View this message in context: 
http://www.nabble.com/How-to-read-stored-functions-tf4513863.html#a12881540
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.