Re: [R] Official way to set/retrieve options in packages?

2013-10-18 Thread Jonathan Greenberg
Wanted to re-start this thread a bit, since I'm still not exactly sure
the best approach to my problem -- basically, the parameters I'm try
to make persistent are installation locations of a particular command
line program that is not installed along with an R package I'm working
on (GDAL, for those of you who are interested in the specifics).  The
function tries to dummy-proof this process by doing a (mostly)
brute-force search of the user's drive for the program location the
first time it executes, and then stores this information (the path to
a given executable) in an option for use with other functions.   This
search process can take some time, so I'd prefer to have this option
set in a semi-permanent way (so it persists between sessions).

Now, Brian Ripley suggested modifying the .Rprofile, but Bert Guntner
suggested this might not be a welcome behavior.  Given that, on an
operating system level, there are often per-program directories for
preferences, would it follow that it might make sense to store
package-options in some standardized location?  If so, where might
this be?  Would it make sense to drop then in the package directory?

Is this a discussion that should move over to r-developers?

--j

On Sat, Jun 1, 2013 at 4:57 PM, Prof Brian Ripley rip...@stats.ox.ac.uk wrote:
 On 01/06/2013 22:44, Anthony Damico wrote:
 hope this helps..  :)

  # define an object `x`
  x - list( any value here , 10 )

  # set `myoption` to that object
  options( myoption = x )

  # retrieve it later (perhaps within a function elsewhere in the package)
  ( y - getOption( myoption ) )


 it's nice to name your options `mypackage.myoption` so users know what
 package the option is associated with in case they type `options()`


 here's the `.onLoad` function in the R survey package.  notice how the
 options are only set *if* they don't already exist--

 But a nicer convention is that used by most packages in R itself: if the
 option is not set, the function using it assumes a suitable default.
 That would make sense for all the FALSE defaults below.

 Note though that this is not 'persistent': users have to set options in
 their startup files (see ?Startup).   There is no official location to
 store package configurations.  Users generally dislike software saving
 settings in their own file space so it seems very much preferable to use
 the standard R mechanisms (.Rprofile etc).


 survey:::.onLoad

 function (...)
 {
  if (is.null(getOption(survey.lonely.psu)))
 options(survey.lonely.psu = fail)
  if (is.null(getOption(survey.ultimate.cluster)))
 options(survey.ultimate.cluster = FALSE)
  if (is.null(getOption(survey.want.obsolete)))
 options(survey.want.obsolete = FALSE)
  if (is.null(getOption(survey.adjust.domain.lonely)))
 options(survey.adjust.domain.lonely = FALSE)
  if (is.null(getOption(survey.drop.replicates)))
 options(survey.drop.replicates = TRUE)
  if (is.null(getOption(survey.multicore)))
 options(survey.multicore = FALSE)
  if (is.null(getOption(survey.replicates.mse)))
 options(survey.replicates.mse = FALSE)
 }
 environment: namespace:survey




 On Sat, Jun 1, 2013 at 4:01 PM, Jonathan Greenberg j...@illinois.eduwrote:

 R-helpers:

 Say I'm developing a package that has a set of user-definable options that
 I would like to be persistent across R-invocations (they are saved
 someplace).  Of course, I can create a little text file to be written/read,
 but I was wondering if there is an officially sanctioned way to do this?
   I see there is an options() and getOptions() function, but I'm unclear how
 I would use this in my own package to create/save new options for my
 particular package.  Cheers!

 --j

 --
 Jonathan A. Greenberg, PhD
 Assistant Professor
 Global Environmental Analysis and Remote Sensing (GEARS) Laboratory
 Department of Geography and Geographic Information Science
 University of Illinois at Urbana-Champaign
 607 South Mathews Avenue, MC 150
 Urbana, IL 61801
 Phone: 217-300-1924
 http://www.geog.illinois.edu/~jgrn/
 AIM: jgrn307, MSN: jgrn...@hotmail.com, Gchat: jgrn307, Skype: jgrn3007

  [[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.


   [[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.



 --
 Brian D. Ripley,  rip...@stats.ox.ac.uk
 Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
 University of Oxford, Tel:  +44 1865 272861 (self)
 1 South Parks 

Re: [R] Official way to set/retrieve options in packages?

2013-10-18 Thread Bert Gunter
1. I do not recall saying any such thing.

2. HOWEVER, no matter. There is no choice. Follow Brian's advice.

-- Bert

On Fri, Oct 18, 2013 at 3:46 PM, Jonathan Greenberg j...@illinois.edu wrote:
 Wanted to re-start this thread a bit, since I'm still not exactly sure
 the best approach to my problem -- basically, the parameters I'm try
 to make persistent are installation locations of a particular command
 line program that is not installed along with an R package I'm working
 on (GDAL, for those of you who are interested in the specifics).  The
 function tries to dummy-proof this process by doing a (mostly)
 brute-force search of the user's drive for the program location the
 first time it executes, and then stores this information (the path to
 a given executable) in an option for use with other functions.   This
 search process can take some time, so I'd prefer to have this option
 set in a semi-permanent way (so it persists between sessions).

 Now, Brian Ripley suggested modifying the .Rprofile, but Bert Guntner
 suggested this might not be a welcome behavior.  Given that, on an
 operating system level, there are often per-program directories for
 preferences, would it follow that it might make sense to store
 package-options in some standardized location?  If so, where might
 this be?  Would it make sense to drop then in the package directory?

 Is this a discussion that should move over to r-developers?

 --j

 On Sat, Jun 1, 2013 at 4:57 PM, Prof Brian Ripley rip...@stats.ox.ac.uk 
 wrote:
 On 01/06/2013 22:44, Anthony Damico wrote:
 hope this helps..  :)

  # define an object `x`
  x - list( any value here , 10 )

  # set `myoption` to that object
  options( myoption = x )

  # retrieve it later (perhaps within a function elsewhere in the 
 package)
  ( y - getOption( myoption ) )


 it's nice to name your options `mypackage.myoption` so users know what
 package the option is associated with in case they type `options()`


 here's the `.onLoad` function in the R survey package.  notice how the
 options are only set *if* they don't already exist--

 But a nicer convention is that used by most packages in R itself: if the
 option is not set, the function using it assumes a suitable default.
 That would make sense for all the FALSE defaults below.

 Note though that this is not 'persistent': users have to set options in
 their startup files (see ?Startup).   There is no official location to
 store package configurations.  Users generally dislike software saving
 settings in their own file space so it seems very much preferable to use
 the standard R mechanisms (.Rprofile etc).


 survey:::.onLoad

 function (...)
 {
  if (is.null(getOption(survey.lonely.psu)))
 options(survey.lonely.psu = fail)
  if (is.null(getOption(survey.ultimate.cluster)))
 options(survey.ultimate.cluster = FALSE)
  if (is.null(getOption(survey.want.obsolete)))
 options(survey.want.obsolete = FALSE)
  if (is.null(getOption(survey.adjust.domain.lonely)))
 options(survey.adjust.domain.lonely = FALSE)
  if (is.null(getOption(survey.drop.replicates)))
 options(survey.drop.replicates = TRUE)
  if (is.null(getOption(survey.multicore)))
 options(survey.multicore = FALSE)
  if (is.null(getOption(survey.replicates.mse)))
 options(survey.replicates.mse = FALSE)
 }
 environment: namespace:survey




 On Sat, Jun 1, 2013 at 4:01 PM, Jonathan Greenberg j...@illinois.eduwrote:

 R-helpers:

 Say I'm developing a package that has a set of user-definable options that
 I would like to be persistent across R-invocations (they are saved
 someplace).  Of course, I can create a little text file to be written/read,
 but I was wondering if there is an officially sanctioned way to do this?
   I see there is an options() and getOptions() function, but I'm unclear 
 how
 I would use this in my own package to create/save new options for my
 particular package.  Cheers!

 --j

 --
 Jonathan A. Greenberg, PhD
 Assistant Professor
 Global Environmental Analysis and Remote Sensing (GEARS) Laboratory
 Department of Geography and Geographic Information Science
 University of Illinois at Urbana-Champaign
 607 South Mathews Avenue, MC 150
 Urbana, IL 61801
 Phone: 217-300-1924
 http://www.geog.illinois.edu/~jgrn/
 AIM: jgrn307, MSN: jgrn...@hotmail.com, Gchat: jgrn307, Skype: jgrn3007

  [[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.


   [[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, 

Re: [R] Official way to set/retrieve options in packages?

2013-10-18 Thread Duncan Murdoch

On 13-10-18 6:46 PM, Jonathan Greenberg wrote:

Wanted to re-start this thread a bit, since I'm still not exactly sure
the best approach to my problem -- basically, the parameters I'm try
to make persistent are installation locations of a particular command
line program that is not installed along with an R package I'm working
on (GDAL, for those of you who are interested in the specifics).  The
function tries to dummy-proof this process by doing a (mostly)
brute-force search of the user's drive for the program location the
first time it executes, and then stores this information (the path to
a given executable) in an option for use with other functions.   This
search process can take some time, so I'd prefer to have this option
set in a semi-permanent way (so it persists between sessions).

Now, Brian Ripley suggested modifying the .Rprofile, but Bert Guntner
suggested this might not be a welcome behavior.  Given that, on an
operating system level, there are often per-program directories for
preferences, would it follow that it might make sense to store
package-options in some standardized location?  If so, where might
this be?  Would it make sense to drop then in the package directory?


No.



Is this a discussion that should move over to r-developers?


Yes.

Duncan Murdoch



--j

On Sat, Jun 1, 2013 at 4:57 PM, Prof Brian Ripley rip...@stats.ox.ac.uk wrote:

On 01/06/2013 22:44, Anthony Damico wrote:

hope this helps..  :)

  # define an object `x`
  x - list( any value here , 10 )

  # set `myoption` to that object
  options( myoption = x )

  # retrieve it later (perhaps within a function elsewhere in the package)
  ( y - getOption( myoption ) )


it's nice to name your options `mypackage.myoption` so users know what
package the option is associated with in case they type `options()`


here's the `.onLoad` function in the R survey package.  notice how the
options are only set *if* they don't already exist--


But a nicer convention is that used by most packages in R itself: if the
option is not set, the function using it assumes a suitable default.
That would make sense for all the FALSE defaults below.

Note though that this is not 'persistent': users have to set options in
their startup files (see ?Startup).   There is no official location to
store package configurations.  Users generally dislike software saving
settings in their own file space so it seems very much preferable to use
the standard R mechanisms (.Rprofile etc).




survey:::.onLoad


function (...)
{
  if (is.null(getOption(survey.lonely.psu)))
options(survey.lonely.psu = fail)
  if (is.null(getOption(survey.ultimate.cluster)))
options(survey.ultimate.cluster = FALSE)
  if (is.null(getOption(survey.want.obsolete)))
options(survey.want.obsolete = FALSE)
  if (is.null(getOption(survey.adjust.domain.lonely)))
options(survey.adjust.domain.lonely = FALSE)
  if (is.null(getOption(survey.drop.replicates)))
options(survey.drop.replicates = TRUE)
  if (is.null(getOption(survey.multicore)))
options(survey.multicore = FALSE)
  if (is.null(getOption(survey.replicates.mse)))
options(survey.replicates.mse = FALSE)
}
environment: namespace:survey




On Sat, Jun 1, 2013 at 4:01 PM, Jonathan Greenberg j...@illinois.eduwrote:


R-helpers:

Say I'm developing a package that has a set of user-definable options that
I would like to be persistent across R-invocations (they are saved
someplace).  Of course, I can create a little text file to be written/read,
but I was wondering if there is an officially sanctioned way to do this?
   I see there is an options() and getOptions() function, but I'm unclear how
I would use this in my own package to create/save new options for my
particular package.  Cheers!

--j

--
Jonathan A. Greenberg, PhD
Assistant Professor
Global Environmental Analysis and Remote Sensing (GEARS) Laboratory
Department of Geography and Geographic Information Science
University of Illinois at Urbana-Champaign
607 South Mathews Avenue, MC 150
Urbana, IL 61801
Phone: 217-300-1924
http://www.geog.illinois.edu/~jgrn/
AIM: jgrn307, MSN: jgrn...@hotmail.com, Gchat: jgrn307, Skype: jgrn3007

  [[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.



   [[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.




--
Brian D. Ripley,  rip...@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 

Re: [R] Official way to set/retrieve options in packages?

2013-06-02 Thread Jonathan Greenberg
What would be an example of setting, saving, and re-loading an option to a
user's .Rprofile -- and would this be a no-no in a CRAN package?

--j


On Sat, Jun 1, 2013 at 4:57 PM, Prof Brian Ripley rip...@stats.ox.ac.ukwrote:

 On 01/06/2013 22:44, Anthony Damico wrote:
  hope this helps..  :)
 
   # define an object `x`
   x - list( any value here , 10 )
 
   # set `myoption` to that object
   options( myoption = x )
 
   # retrieve it later (perhaps within a function elsewhere in the
 package)
   ( y - getOption( myoption ) )
 
 
  it's nice to name your options `mypackage.myoption` so users know what
  package the option is associated with in case they type `options()`
 
 
  here's the `.onLoad` function in the R survey package.  notice how the
  options are only set *if* they don't already exist--

 But a nicer convention is that used by most packages in R itself: if the
 option is not set, the function using it assumes a suitable default.
 That would make sense for all the FALSE defaults below.

 Note though that this is not 'persistent': users have to set options in
 their startup files (see ?Startup).   There is no official location to
 store package configurations.  Users generally dislike software saving
 settings in their own file space so it seems very much preferable to use
 the standard R mechanisms (.Rprofile etc).

 
  survey:::.onLoad
 
  function (...)
  {
   if (is.null(getOption(survey.lonely.psu)))
  options(survey.lonely.psu = fail)
   if (is.null(getOption(survey.ultimate.cluster)))
  options(survey.ultimate.cluster = FALSE)
   if (is.null(getOption(survey.want.obsolete)))
  options(survey.want.obsolete = FALSE)
   if (is.null(getOption(survey.adjust.domain.lonely)))
  options(survey.adjust.domain.lonely = FALSE)
   if (is.null(getOption(survey.drop.replicates)))
  options(survey.drop.replicates = TRUE)
   if (is.null(getOption(survey.multicore)))
  options(survey.multicore = FALSE)
   if (is.null(getOption(survey.replicates.mse)))
  options(survey.replicates.mse = FALSE)
  }
  environment: namespace:survey
 
 
 
 
  On Sat, Jun 1, 2013 at 4:01 PM, Jonathan Greenberg j...@illinois.edu
 wrote:
 
  R-helpers:
 
  Say I'm developing a package that has a set of user-definable options
 that
  I would like to be persistent across R-invocations (they are saved
  someplace).  Of course, I can create a little text file to be
 written/read,
  but I was wondering if there is an officially sanctioned way to do
 this?
I see there is an options() and getOptions() function, but I'm
 unclear how
  I would use this in my own package to create/save new options for my
  particular package.  Cheers!
 
  --j
 
  --
  Jonathan A. Greenberg, PhD
  Assistant Professor
  Global Environmental Analysis and Remote Sensing (GEARS) Laboratory
  Department of Geography and Geographic Information Science
  University of Illinois at Urbana-Champaign
  607 South Mathews Avenue, MC 150
  Urbana, IL 61801
  Phone: 217-300-1924
  http://www.geog.illinois.edu/~jgrn/
  AIM: jgrn307, MSN: jgrn...@hotmail.com, Gchat: jgrn307, Skype: jgrn3007
 
   [[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.
 
 
[[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.
 


 --
 Brian D. Ripley,  rip...@stats.ox.ac.uk
 Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
 University of Oxford, Tel:  +44 1865 272861 (self)
 1 South Parks Road, +44 1865 272866 (PA)
 Oxford OX1 3TG, UKFax:  +44 1865 272595




-- 
Jonathan A. Greenberg, PhD
Assistant Professor
Global Environmental Analysis and Remote Sensing (GEARS) Laboratory
Department of Geography and Geographic Information Science
University of Illinois at Urbana-Champaign
607 South Mathews Avenue, MC 150
Urbana, IL 61801
Phone: 217-300-1924
http://www.geog.illinois.edu/~jgrn/
AIM: jgrn307, MSN: jgrn...@hotmail.com, Gchat: jgrn307, Skype: jgrn3007

[[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] Official way to set/retrieve options in packages?

2013-06-02 Thread Bert Gunter
Have you read

?Startup

which explains startup procedures, including reading of .Rprofile.

I cannot speak for Brian Ripley, but I can tell you that I would
prefer that packages did not mess with my .Rprofile files.

OTOH, I have no objections if packages suggest that I set certain
options in them or even give me lines of code that I can add if I
choose ( or give me an option to call a function to do so).

I understand that this is not the automatic procedure you seem to be seeking...

Cheers,
Bert

On Sun, Jun 2, 2013 at 9:06 AM, Jonathan Greenberg j...@illinois.edu wrote:
 What would be an example of setting, saving, and re-loading an option to a
 user's .Rprofile -- and would this be a no-no in a CRAN package?

 --j


 On Sat, Jun 1, 2013 at 4:57 PM, Prof Brian Ripley 
 rip...@stats.ox.ac.ukwrote:

 On 01/06/2013 22:44, Anthony Damico wrote:
  hope this helps..  :)
 
   # define an object `x`
   x - list( any value here , 10 )
 
   # set `myoption` to that object
   options( myoption = x )
 
   # retrieve it later (perhaps within a function elsewhere in the
 package)
   ( y - getOption( myoption ) )
 
 
  it's nice to name your options `mypackage.myoption` so users know what
  package the option is associated with in case they type `options()`
 
 
  here's the `.onLoad` function in the R survey package.  notice how the
  options are only set *if* they don't already exist--

 But a nicer convention is that used by most packages in R itself: if the
 option is not set, the function using it assumes a suitable default.
 That would make sense for all the FALSE defaults below.

 Note though that this is not 'persistent': users have to set options in
 their startup files (see ?Startup).   There is no official location to
 store package configurations.  Users generally dislike software saving
 settings in their own file space so it seems very much preferable to use
 the standard R mechanisms (.Rprofile etc).

 
  survey:::.onLoad
 
  function (...)
  {
   if (is.null(getOption(survey.lonely.psu)))
  options(survey.lonely.psu = fail)
   if (is.null(getOption(survey.ultimate.cluster)))
  options(survey.ultimate.cluster = FALSE)
   if (is.null(getOption(survey.want.obsolete)))
  options(survey.want.obsolete = FALSE)
   if (is.null(getOption(survey.adjust.domain.lonely)))
  options(survey.adjust.domain.lonely = FALSE)
   if (is.null(getOption(survey.drop.replicates)))
  options(survey.drop.replicates = TRUE)
   if (is.null(getOption(survey.multicore)))
  options(survey.multicore = FALSE)
   if (is.null(getOption(survey.replicates.mse)))
  options(survey.replicates.mse = FALSE)
  }
  environment: namespace:survey
 
 
 
 
  On Sat, Jun 1, 2013 at 4:01 PM, Jonathan Greenberg j...@illinois.edu
 wrote:
 
  R-helpers:
 
  Say I'm developing a package that has a set of user-definable options
 that
  I would like to be persistent across R-invocations (they are saved
  someplace).  Of course, I can create a little text file to be
 written/read,
  but I was wondering if there is an officially sanctioned way to do
 this?
I see there is an options() and getOptions() function, but I'm
 unclear how
  I would use this in my own package to create/save new options for my
  particular package.  Cheers!
 
  --j
 
  --
  Jonathan A. Greenberg, PhD
  Assistant Professor
  Global Environmental Analysis and Remote Sensing (GEARS) Laboratory
  Department of Geography and Geographic Information Science
  University of Illinois at Urbana-Champaign
  607 South Mathews Avenue, MC 150
  Urbana, IL 61801
  Phone: 217-300-1924
  http://www.geog.illinois.edu/~jgrn/
  AIM: jgrn307, MSN: jgrn...@hotmail.com, Gchat: jgrn307, Skype: jgrn3007
 
   [[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.
 
 
[[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.
 


 --
 Brian D. Ripley,  rip...@stats.ox.ac.uk
 Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
 University of Oxford, Tel:  +44 1865 272861 (self)
 1 South Parks Road, +44 1865 272866 (PA)
 Oxford OX1 3TG, UKFax:  +44 1865 272595




 --
 Jonathan A. Greenberg, PhD
 Assistant Professor
 Global Environmental Analysis and Remote Sensing (GEARS) Laboratory
 Department of Geography and Geographic Information Science
 University of Illinois at Urbana-Champaign
 607 South Mathews Avenue, MC 150
 Urbana, IL 61801
 Phone: 

[R] Official way to set/retrieve options in packages?

2013-06-01 Thread Jonathan Greenberg
R-helpers:

Say I'm developing a package that has a set of user-definable options that
I would like to be persistent across R-invocations (they are saved
someplace).  Of course, I can create a little text file to be written/read,
but I was wondering if there is an officially sanctioned way to do this?
 I see there is an options() and getOptions() function, but I'm unclear how
I would use this in my own package to create/save new options for my
particular package.  Cheers!

--j

-- 
Jonathan A. Greenberg, PhD
Assistant Professor
Global Environmental Analysis and Remote Sensing (GEARS) Laboratory
Department of Geography and Geographic Information Science
University of Illinois at Urbana-Champaign
607 South Mathews Avenue, MC 150
Urbana, IL 61801
Phone: 217-300-1924
http://www.geog.illinois.edu/~jgrn/
AIM: jgrn307, MSN: jgrn...@hotmail.com, Gchat: jgrn307, Skype: jgrn3007

[[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] Official way to set/retrieve options in packages?

2013-06-01 Thread Anthony Damico
hope this helps..  :)

# define an object `x`
x - list( any value here , 10 )

# set `myoption` to that object
options( myoption = x )

# retrieve it later (perhaps within a function elsewhere in the package)
( y - getOption( myoption ) )


it's nice to name your options `mypackage.myoption` so users know what
package the option is associated with in case they type `options()`


here's the `.onLoad` function in the R survey package.  notice how the
options are only set *if* they don't already exist--

 survey:::.onLoad

function (...)
{
if (is.null(getOption(survey.lonely.psu)))
options(survey.lonely.psu = fail)
if (is.null(getOption(survey.ultimate.cluster)))
options(survey.ultimate.cluster = FALSE)
if (is.null(getOption(survey.want.obsolete)))
options(survey.want.obsolete = FALSE)
if (is.null(getOption(survey.adjust.domain.lonely)))
options(survey.adjust.domain.lonely = FALSE)
if (is.null(getOption(survey.drop.replicates)))
options(survey.drop.replicates = TRUE)
if (is.null(getOption(survey.multicore)))
options(survey.multicore = FALSE)
if (is.null(getOption(survey.replicates.mse)))
options(survey.replicates.mse = FALSE)
}
environment: namespace:survey




On Sat, Jun 1, 2013 at 4:01 PM, Jonathan Greenberg j...@illinois.eduwrote:

 R-helpers:

 Say I'm developing a package that has a set of user-definable options that
 I would like to be persistent across R-invocations (they are saved
 someplace).  Of course, I can create a little text file to be written/read,
 but I was wondering if there is an officially sanctioned way to do this?
  I see there is an options() and getOptions() function, but I'm unclear how
 I would use this in my own package to create/save new options for my
 particular package.  Cheers!

 --j

 --
 Jonathan A. Greenberg, PhD
 Assistant Professor
 Global Environmental Analysis and Remote Sensing (GEARS) Laboratory
 Department of Geography and Geographic Information Science
 University of Illinois at Urbana-Champaign
 607 South Mathews Avenue, MC 150
 Urbana, IL 61801
 Phone: 217-300-1924
 http://www.geog.illinois.edu/~jgrn/
 AIM: jgrn307, MSN: jgrn...@hotmail.com, Gchat: jgrn307, Skype: jgrn3007

 [[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.


[[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] Official way to set/retrieve options in packages?

2013-06-01 Thread Prof Brian Ripley

On 01/06/2013 22:44, Anthony Damico wrote:

hope this helps..  :)

 # define an object `x`
 x - list( any value here , 10 )

 # set `myoption` to that object
 options( myoption = x )

 # retrieve it later (perhaps within a function elsewhere in the package)
 ( y - getOption( myoption ) )


it's nice to name your options `mypackage.myoption` so users know what
package the option is associated with in case they type `options()`


here's the `.onLoad` function in the R survey package.  notice how the
options are only set *if* they don't already exist--


But a nicer convention is that used by most packages in R itself: if the 
option is not set, the function using it assumes a suitable default. 
That would make sense for all the FALSE defaults below.


Note though that this is not 'persistent': users have to set options in 
their startup files (see ?Startup).   There is no official location to 
store package configurations.  Users generally dislike software saving 
settings in their own file space so it seems very much preferable to use 
the standard R mechanisms (.Rprofile etc).





survey:::.onLoad


function (...)
{
 if (is.null(getOption(survey.lonely.psu)))
options(survey.lonely.psu = fail)
 if (is.null(getOption(survey.ultimate.cluster)))
options(survey.ultimate.cluster = FALSE)
 if (is.null(getOption(survey.want.obsolete)))
options(survey.want.obsolete = FALSE)
 if (is.null(getOption(survey.adjust.domain.lonely)))
options(survey.adjust.domain.lonely = FALSE)
 if (is.null(getOption(survey.drop.replicates)))
options(survey.drop.replicates = TRUE)
 if (is.null(getOption(survey.multicore)))
options(survey.multicore = FALSE)
 if (is.null(getOption(survey.replicates.mse)))
options(survey.replicates.mse = FALSE)
}
environment: namespace:survey




On Sat, Jun 1, 2013 at 4:01 PM, Jonathan Greenberg j...@illinois.eduwrote:


R-helpers:

Say I'm developing a package that has a set of user-definable options that
I would like to be persistent across R-invocations (they are saved
someplace).  Of course, I can create a little text file to be written/read,
but I was wondering if there is an officially sanctioned way to do this?
  I see there is an options() and getOptions() function, but I'm unclear how
I would use this in my own package to create/save new options for my
particular package.  Cheers!

--j

--
Jonathan A. Greenberg, PhD
Assistant Professor
Global Environmental Analysis and Remote Sensing (GEARS) Laboratory
Department of Geography and Geographic Information Science
University of Illinois at Urbana-Champaign
607 South Mathews Avenue, MC 150
Urbana, IL 61801
Phone: 217-300-1924
http://www.geog.illinois.edu/~jgrn/
AIM: jgrn307, MSN: jgrn...@hotmail.com, Gchat: jgrn307, Skype: jgrn3007

 [[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.



[[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.




--
Brian D. Ripley,  rip...@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

__
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.