adding environment variables
3
0
Entering edit mode
@robert-m-flight-4158
Last seen 5 months ago
United States
Hi All, I am developing a package that requires information about the location of a set of files that will be used often in the calculations. In my current version, I define the location in the main file that calls all the subfunctions. This works fine when you are installing from source, but will not work so well if I want people to be able to install binary versions of the package. Therefore, I think the best way to encode the information would be through the use of an environment variable, that could then be read by "Sys.getenv(VARIABLE)" when the function is called. In the help, I found a few different ways to set environment variables, but the easiest way (from my reading anyways) seemed to be by creating the file "Renviron.site" in the R_HOME/etc directory and adding the variable there. I am interested in opinions from the list, or other suggestions on how to do this. For those who are interested, the package does a lot of parsing of KEGG KGML files, and to speed up calculations I offer advice that they should download a copy of the KGML directory for their organism to their local machine, and I want the package to know where those files are at runtime. Thanks in advance, -Robert Robert M. Flight, Ph.D. University of Louisville Bioinformatics Laboratory University of Louisville Louisville, KY PH 502-852-0467 EM robert.flight at louisville.edu EM rflight79 at gmail.com Williams and Holland's Law: ? ? ?? If enough data is collected, anything may be proven by statistical methods.
Organism Organism • 1.4k views
ADD COMMENT
0
Entering edit mode
@sean-davis-490
Last seen 12 weeks ago
United States
On Thu, Oct 28, 2010 at 10:21 AM, Robert M. Flight <rflight79@gmail.com>wrote: > Hi All, > > I am developing a package that requires information about the location > of a set of files that will be used often in the calculations. In my > current version, I define the location in the main file that calls all > the subfunctions. This works fine when you are installing from source, > but will not work so well if I want people to be able to install > binary versions of the package. Therefore, I think the best way to > encode the information would be through the use of an environment > variable, that could then be read by "Sys.getenv(VARIABLE)" when the > function is called. > > In the help, I found a few different ways to set environment > variables, but the easiest way (from my reading anyways) seemed to be > by creating the file "Renviron.site" in the R_HOME/etc directory and > adding the variable there. I am interested in opinions from the list, > or other suggestions on how to do this. > > For those who are interested, the package does a lot of parsing of > KEGG KGML files, and to speed up calculations I offer advice that they > should download a copy of the KGML directory for their organism to > their local machine, and I want the package to know where those files > are at runtime. > > You could also use an option or set of options. See ?options for details. Sean > Thanks in advance, > > -Robert > > Robert M. Flight, Ph.D. > University of Louisville Bioinformatics Laboratory > University of Louisville > Louisville, KY > > PH 502-852-0467 > EM robert.flight@louisville.edu > EM rflight79@gmail.com > > Williams and Holland's Law: > If enough data is collected, anything may be proven by > statistical methods. > > _______________________________________________ > Bioconductor mailing list > Bioconductor@stat.math.ethz.ch > https://stat.ethz.ch/mailman/listinfo/bioconductor > Search the archives: > http://news.gmane.org/gmane.science.biology.informatics.conductor > [[alternative HTML version deleted]]
ADD COMMENT
0
Entering edit mode
On 10/28/2010 07:40 AM, Sean Davis wrote: > On Thu, Oct 28, 2010 at 10:21 AM, Robert M. Flight <rflight79 at="" gmail.com="">wrote: > >> Hi All, >> >> I am developing a package that requires information about the location >> of a set of files that will be used often in the calculations. In my >> current version, I define the location in the main file that calls all >> the subfunctions. This works fine when you are installing from source, >> but will not work so well if I want people to be able to install >> binary versions of the package. Therefore, I think the best way to >> encode the information would be through the use of an environment >> variable, that could then be read by "Sys.getenv(VARIABLE)" when the >> function is called. >> >> In the help, I found a few different ways to set environment >> variables, but the easiest way (from my reading anyways) seemed to be >> by creating the file "Renviron.site" in the R_HOME/etc directory and >> adding the variable there. I am interested in opinions from the list, >> or other suggestions on how to do this. >> >> For those who are interested, the package does a lot of parsing of >> KEGG KGML files, and to speed up calculations I offer advice that they >> should download a copy of the KGML directory for their organism to >> their local machine, and I want the package to know where those files >> are at runtime. >> >> > You could also use an option or set of options. See ?options for details. Or define an environment to store relevant information and accessors for you / the user to set / get .kgmlOptions <- new.env(parent=emptyenv()) setKgmlLocalRepository <- function(x) .kgmlOptions[["localRepository"]] <- normalizePath(x) getKgmlLocalRepository <- function() .kgmlOptions[["localRepository"]] If there's just the single option then active bindings could be fun, in a package implemented I think as .onLoad <- function(...) { makeActiveBinding("kgmlLocalRepository", function(x) { if (missing(x)) .kgmlOptions[["localRepository"]] else .kgmlOptions[["localRepository"]] <- normalizePath(x) }, topenv(parent.frame())) } and used as any variable, both in and outside the package. kgmlLocalRepository <- "some-dir" kgmlLocalRepository This latter is probably too clever -- the user isn't aware enough that they're setting a package-global variable. Martin > > Sean > > >> Thanks in advance, >> >> -Robert >> >> Robert M. Flight, Ph.D. >> University of Louisville Bioinformatics Laboratory >> University of Louisville >> Louisville, KY >> >> PH 502-852-0467 >> EM robert.flight at louisville.edu >> EM rflight79 at gmail.com >> >> Williams and Holland's Law: >> If enough data is collected, anything may be proven by >> statistical methods. >> >> _______________________________________________ >> Bioconductor mailing list >> Bioconductor at stat.math.ethz.ch >> https://stat.ethz.ch/mailman/listinfo/bioconductor >> Search the archives: >> http://news.gmane.org/gmane.science.biology.informatics.conductor >> > > [[alternative HTML version deleted]] > > _______________________________________________ > Bioconductor mailing list > Bioconductor at stat.math.ethz.ch > https://stat.ethz.ch/mailman/listinfo/bioconductor > Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor -- Computational Biology Fred Hutchinson Cancer Research Center 1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109 Location: M1-B861 Telephone: 206 667-2793
ADD REPLY
0
Entering edit mode
Wow, I see what you are doing there, and it looks like it would be a good way to do it. I may investigate that in the future. In the interest of staying simple and what I can figure out right now that would work, I actually went with the suggestion of using an object to store the information. This object is created by a very simple function, and is stored in the directory of the package. It is easy to modify the object, and only has to be done once after installation, if it is even used. Thanks for the suggestions. -Robert Robert M. Flight, Ph.D. University of Louisville Bioinformatics Laboratory University of Louisville Louisville, KY PH 502-852-0467 EM robert.flight at louisville.edu EM rflight79 at gmail.com Williams and Holland's Law: ? ? ?? If enough data is collected, anything may be proven by statistical methods. On Thu, Oct 28, 2010 at 12:49, Martin Morgan <mtmorgan at="" fhcrc.org=""> wrote: > On 10/28/2010 07:40 AM, Sean Davis wrote: >> On Thu, Oct 28, 2010 at 10:21 AM, Robert M. Flight <rflight79 at="" gmail.com="">wrote: >> >>> Hi All, >>> >>> I am developing a package that requires information about the location >>> of a set of files that will be used often in the calculations. In my >>> current version, I define the location in the main file that calls all >>> the subfunctions. This works fine when you are installing from source, >>> but will not work so well if I want people to be able to install >>> binary versions of the package. Therefore, I think the best way to >>> encode the information would be through the use of an environment >>> variable, that could then be read by "Sys.getenv(VARIABLE)" when the >>> function is called. >>> >>> In the help, I found a few different ways to set environment >>> variables, but the easiest way (from my reading anyways) seemed to be >>> by creating the file "Renviron.site" in the R_HOME/etc directory and >>> adding the variable there. I am interested in opinions from the list, >>> or other suggestions on how to do this. >>> >>> For those who are interested, the package does a lot of parsing of >>> KEGG KGML files, and to speed up calculations I offer advice that they >>> should download a copy of the KGML directory for their organism to >>> their local machine, and I want the package to know where those files >>> are at runtime. >>> >>> >> You could also use an option or set of options. ?See ?options for details. > > Or define an environment to store relevant information and accessors for > you / the user to set / get > > .kgmlOptions <- new.env(parent=emptyenv()) > > setKgmlLocalRepository <- > ? ?function(x) .kgmlOptions[["localRepository"]] <- normalizePath(x) > > getKgmlLocalRepository <- > ? ?function() .kgmlOptions[["localRepository"]] > > If there's just the single option then active bindings could be fun, in > a package implemented I think as > > .onLoad <- > ? ?function(...) > { > ? ?makeActiveBinding("kgmlLocalRepository", function(x) { > ? ? ? ?if (missing(x)) .kgmlOptions[["localRepository"]] > ? ? ? ?else .kgmlOptions[["localRepository"]] <- normalizePath(x) > ? ?}, topenv(parent.frame())) > } > > and used as any variable, both in and outside the package. > > kgmlLocalRepository <- "some-dir" > kgmlLocalRepository > > This latter is probably too clever -- the user isn't aware enough that > they're setting a package-global variable. > > Martin > >> >> Sean >> >> >>> Thanks in advance, >>> >>> -Robert >>> >>> Robert M. Flight, Ph.D. >>> University of Louisville Bioinformatics Laboratory >>> University of Louisville >>> Louisville, KY >>> >>> PH 502-852-0467 >>> EM robert.flight at louisville.edu >>> EM rflight79 at gmail.com >>> >>> Williams and Holland's Law: >>> ? ? ? ?If enough data is collected, anything may be proven by >>> statistical methods. >>> >>> _______________________________________________ >>> Bioconductor mailing list >>> Bioconductor at stat.math.ethz.ch >>> https://stat.ethz.ch/mailman/listinfo/bioconductor >>> Search the archives: >>> http://news.gmane.org/gmane.science.biology.informatics.conductor >>> >> >> ? ? ? [[alternative HTML version deleted]] >> >> _______________________________________________ >> Bioconductor mailing list >> Bioconductor at stat.math.ethz.ch >> https://stat.ethz.ch/mailman/listinfo/bioconductor >> Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor > > > -- > Computational Biology > Fred Hutchinson Cancer Research Center > 1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109 > > Location: M1-B861 > Telephone: 206 667-2793 >
ADD REPLY
0
Entering edit mode
You cannot expect the user to have write permission to the package installation directory. This won't work on most multi-user systems. I was thinking of an object in the user's workspace. Kasper On Thu, Oct 28, 2010 at 3:38 PM, Robert M. Flight <rflight79 at="" gmail.com=""> wrote: > Wow, I see what you are doing there, and it looks like it would be a > good way to do it. I may investigate that in the future. > > In the interest of staying simple and what I can figure out right now > that would work, I actually went with the suggestion of using an > object to store the information. This object is created by a very > simple function, and is stored in the directory of the package. It is > easy to modify the object, and only has to be done once after > installation, if it is even used. > > Thanks for the suggestions. > > -Robert > > Robert M. Flight, Ph.D. > University of Louisville Bioinformatics Laboratory > University of Louisville > Louisville, KY > > PH 502-852-0467 > EM robert.flight at louisville.edu > EM rflight79 at gmail.com > > Williams and Holland's Law: > ? ? ?? If enough data is collected, anything may be proven by > statistical methods. > > > > On Thu, Oct 28, 2010 at 12:49, Martin Morgan <mtmorgan at="" fhcrc.org=""> wrote: >> On 10/28/2010 07:40 AM, Sean Davis wrote: >>> On Thu, Oct 28, 2010 at 10:21 AM, Robert M. Flight <rflight79 at="" gmail.com="">wrote: >>> >>>> Hi All, >>>> >>>> I am developing a package that requires information about the location >>>> of a set of files that will be used often in the calculations. In my >>>> current version, I define the location in the main file that calls all >>>> the subfunctions. This works fine when you are installing from source, >>>> but will not work so well if I want people to be able to install >>>> binary versions of the package. Therefore, I think the best way to >>>> encode the information would be through the use of an environment >>>> variable, that could then be read by "Sys.getenv(VARIABLE)" when the >>>> function is called. >>>> >>>> In the help, I found a few different ways to set environment >>>> variables, but the easiest way (from my reading anyways) seemed to be >>>> by creating the file "Renviron.site" in the R_HOME/etc directory and >>>> adding the variable there. I am interested in opinions from the list, >>>> or other suggestions on how to do this. >>>> >>>> For those who are interested, the package does a lot of parsing of >>>> KEGG KGML files, and to speed up calculations I offer advice that they >>>> should download a copy of the KGML directory for their organism to >>>> their local machine, and I want the package to know where those files >>>> are at runtime. >>>> >>>> >>> You could also use an option or set of options. ?See ?options for details. >> >> Or define an environment to store relevant information and accessors for >> you / the user to set / get >> >> .kgmlOptions <- new.env(parent=emptyenv()) >> >> setKgmlLocalRepository <- >> ? ?function(x) .kgmlOptions[["localRepository"]] <- normalizePath(x) >> >> getKgmlLocalRepository <- >> ? ?function() .kgmlOptions[["localRepository"]] >> >> If there's just the single option then active bindings could be fun, in >> a package implemented I think as >> >> .onLoad <- >> ? ?function(...) >> { >> ? ?makeActiveBinding("kgmlLocalRepository", function(x) { >> ? ? ? ?if (missing(x)) .kgmlOptions[["localRepository"]] >> ? ? ? ?else .kgmlOptions[["localRepository"]] <- normalizePath(x) >> ? ?}, topenv(parent.frame())) >> } >> >> and used as any variable, both in and outside the package. >> >> kgmlLocalRepository <- "some-dir" >> kgmlLocalRepository >> >> This latter is probably too clever -- the user isn't aware enough that >> they're setting a package-global variable. >> >> Martin >> >>> >>> Sean >>> >>> >>>> Thanks in advance, >>>> >>>> -Robert >>>> >>>> Robert M. Flight, Ph.D. >>>> University of Louisville Bioinformatics Laboratory >>>> University of Louisville >>>> Louisville, KY >>>> >>>> PH 502-852-0467 >>>> EM robert.flight at louisville.edu >>>> EM rflight79 at gmail.com >>>> >>>> Williams and Holland's Law: >>>> ? ? ? ?If enough data is collected, anything may be proven by >>>> statistical methods. >>>> >>>> _______________________________________________ >>>> Bioconductor mailing list >>>> Bioconductor at stat.math.ethz.ch >>>> https://stat.ethz.ch/mailman/listinfo/bioconductor >>>> Search the archives: >>>> http://news.gmane.org/gmane.science.biology.informatics.conductor >>>> >>> >>> ? ? ? [[alternative HTML version deleted]] >>> >>> _______________________________________________ >>> Bioconductor mailing list >>> Bioconductor at stat.math.ethz.ch >>> https://stat.ethz.ch/mailman/listinfo/bioconductor >>> Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor >> >> >> -- >> Computational Biology >> Fred Hutchinson Cancer Research Center >> 1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109 >> >> Location: M1-B861 >> Telephone: 206 667-2793 >> > > _______________________________________________ > Bioconductor mailing list > Bioconductor at stat.math.ethz.ch > https://stat.ethz.ch/mailman/listinfo/bioconductor > Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor >
ADD REPLY
0
Entering edit mode
@kasper-daniel-hansen-2979
Last seen 9 months ago
United States
I would use some object to encode the file location. The object might have additional information as well. Conceptually, this is similar to how biomaRt has a mart object which specifies a biomart server. You can do the same with options or environment variables, however, for your use case I would find it unnatural. Specifically because your files are data as opposed to executables/libraries. Kasper On Thu, Oct 28, 2010 at 10:21 AM, Robert M. Flight <rflight79 at="" gmail.com=""> wrote: > Hi All, > > I am developing a package that requires information about the location > of a set of files that will be used often in the calculations. In my > current version, I define the location in the main file that calls all > the subfunctions. This works fine when you are installing from source, > but will not work so well if I want people to be able to install > binary versions of the package. Therefore, I think the best way to > encode the information would be through the use of an environment > variable, that could then be read by "Sys.getenv(VARIABLE)" when the > function is called. > > In the help, I found a few different ways to set environment > variables, but the easiest way (from my reading anyways) seemed to be > by creating the file "Renviron.site" in the R_HOME/etc directory and > adding the variable there. I am interested in opinions from the list, > or other suggestions on how to do this. > > For those who are interested, the package does a lot of parsing of > KEGG KGML files, and to speed up calculations I offer advice that they > should download a copy of the KGML directory for their organism to > their local machine, and I want the package to know where those files > are at runtime. > > Thanks in advance, > > -Robert > > Robert M. Flight, Ph.D. > University of Louisville Bioinformatics Laboratory > University of Louisville > Louisville, KY > > PH 502-852-0467 > EM robert.flight at louisville.edu > EM rflight79 at gmail.com > > Williams and Holland's Law: > ? ? ?? If enough data is collected, anything may be proven by > statistical methods. > > _______________________________________________ > Bioconductor mailing list > Bioconductor at stat.math.ethz.ch > https://stat.ethz.ch/mailman/listinfo/bioconductor > Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor >
ADD COMMENT
0
Entering edit mode
@henrique-dallazuanna-4326
Last seen 9.6 years ago
Take a look in ?Sys.setenv On Thu, Oct 28, 2010 at 12:21 PM, Robert M. Flight <rflight79@gmail.com>wrote: > Hi All, > > I am developing a package that requires information about the location > of a set of files that will be used often in the calculations. In my > current version, I define the location in the main file that calls all > the subfunctions. This works fine when you are installing from source, > but will not work so well if I want people to be able to install > binary versions of the package. Therefore, I think the best way to > encode the information would be through the use of an environment > variable, that could then be read by "Sys.getenv(VARIABLE)" when the > function is called. > > In the help, I found a few different ways to set environment > variables, but the easiest way (from my reading anyways) seemed to be > by creating the file "Renviron.site" in the R_HOME/etc directory and > adding the variable there. I am interested in opinions from the list, > or other suggestions on how to do this. > > For those who are interested, the package does a lot of parsing of > KEGG KGML files, and to speed up calculations I offer advice that they > should download a copy of the KGML directory for their organism to > their local machine, and I want the package to know where those files > are at runtime. > > Thanks in advance, > > -Robert > > Robert M. Flight, Ph.D. > University of Louisville Bioinformatics Laboratory > University of Louisville > Louisville, KY > > PH 502-852-0467 > EM robert.flight@louisville.edu > EM rflight79@gmail.com > > Williams and Holland's Law: > If enough data is collected, anything may be proven by > statistical methods. > > ______________________________________________ > 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. > -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[alternative HTML version deleted]]
ADD COMMENT

Login before adding your answer.

Traffic: 666 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6