[Rd] Patch to add Beta binomial distribution. Mentor needed!
Hello, I implemented the Beta binomial distribution following the patterns of the binomial distribution code and inspired by JAGS' code [1]. I have studied the code carefully but it's my first run in the R internals. Can somebody review the code and if everything it's ok commit to the repository? [1] http://mcmc-jags.hg.sourceforge.net/hgweb/mcmc-jags/mcmc-jags/file/15af65a4be29/src/modules/bugs/distributions/DBetaBin.cc -- Joan Maspons CREAF (Centre de Recerca Ecològica i Aplicacions Forestals) Universitat Autònoma de Barcelona, 08193 Bellaterra (Barcelona), Catalonia Tel +34 93 581 2915j.masp...@creaf.uab.cat http://www.creaf.uab.cat __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Patch to add Beta binomial distribution. Mentor needed!
Dear Joan, Are you aware of this page http://cran.r-project.org/web/views/Distributions.html ? If you want to contribute to R, you should write a package and submit it to CRAN. See http://cran.r-project.org/doc/manuals/R-exts.html Regards Christophe -- Christophe Dutang Ph.D. student at ISFA, Lyon, France website: http://dutangc.free.fr Le 22 mai 2012 à 12:14, Joan Maspons a écrit : Hello, I implemented the Beta binomial distribution following the patterns of the binomial distribution code and inspired by JAGS' code [1]. I have studied the code carefully but it's my first run in the R internals. Can somebody review the code and if everything it's ok commit to the repository? [1] http://mcmc-jags.hg.sourceforge.net/hgweb/mcmc-jags/mcmc-jags/file/15af65a4be29/src/modules/bugs/distributions/DBetaBin.cc -- Joan Maspons CREAF (Centre de Recerca Ecològica i Aplicacions Forestals) Universitat Autònoma de Barcelona, 08193 Bellaterra (Barcelona), Catalonia Tel +34 93 581 2915j.masp...@creaf.uab.cat http://www.creaf.uab.cat __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Patch to add Beta binomial distribution. Mentor needed!
Hello, 2012/5/22 Christophe Dutang duta...@gmail.com Dear Joan, Are you aware of this page http://cran.r-project.org/web/views/Distributions.html ? Yes, I remember https://stat.ethz.ch/pipermail/r-devel/2012-March/063552.html If you want to contribute to R, you should write a package and submit it to CRAN. See http://cran.r-project.org/doc/manuals/R-exts.html It's necessary to develop a package before to add the functions to R-base? I just want to add beta binomial and beta negative binomial distributions which from my point of view are not more strange than distributions included in R-base. I think they are quite common in order to simulate a binomial or negative binomial process in an stochastic environment. In the other hand I have no experience in writing packages so it would take me more time. Yours, Joan Regards Christophe -- Christophe Dutang Ph.D. student at ISFA, Lyon, France website: http://dutangc.free.fr Le 22 mai 2012 à 12:14, Joan Maspons a écrit : Hello, I implemented the Beta binomial distribution following the patterns of the binomial distribution code and inspired by JAGS' code [1]. I have studied the code carefully but it's my first run in the R internals. Can somebody review the code and if everything it's ok commit to the repository? [1] http://mcmc-jags.hg.sourceforge.net/hgweb/mcmc-jags/mcmc-jags/file/15af65a4be29/src/modules/bugs/distributions/DBetaBin.cc -- Joan Maspons CREAF (Centre de Recerca Ecològica i Aplicacions Forestals) Universitat Autònoma de Barcelona, 08193 Bellaterra (Barcelona), Catalonia Tel +34 93 581 2915j.masp...@creaf.uab.cat http://www.creaf.uab.cat __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel -- Joan Maspons CREAF (Centre de Recerca Ecològica i Aplicacions Forestals) Universitat Autònoma de Barcelona, 08193 Bellaterra (Barcelona), Catalonia Tel +34 93 581 2915j.masp...@creaf.uab.cat http://www.creaf.uab.cat [[alternative HTML version deleted]] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Patch to add Beta binomial distribution. Mentor needed!
On Tue, May 22, 2012 at 8:27 AM, Joan Maspons j.masp...@creaf.uab.cat wrote: Hello, 2012/5/22 Christophe Dutang duta...@gmail.com Dear Joan, snip If you want to contribute to R, you should write a package and submit it to CRAN. See http://cran.r-project.org/doc/manuals/R-exts.html It's necessary to develop a package before to add the functions to R-base? I just want to add beta binomial and beta negative binomial distributions which from my point of view are not more strange than distributions included in R-base. I think they are quite common in order to simulate a binomial or negative binomial process in an stochastic environment. In order to add functions to the main R distribution, you have to convince someone on R-core to maintain the code. In the other hand I have no experience in writing packages so it would take me more time. The actuar package contains many additional distributions. You might see if the maintainer(s) would be interested in incorporating your code (if they don't have that functionality already). Yours, Joan Regards Christophe -- Christophe Dutang Ph.D. student at ISFA, Lyon, France website: http://dutangc.free.fr Le 22 mai 2012 à 12:14, Joan Maspons a écrit : Hello, I implemented the Beta binomial distribution following the patterns of the binomial distribution code and inspired by JAGS' code [1]. I have studied the code carefully but it's my first run in the R internals. Can somebody review the code and if everything it's ok commit to the repository? [1] http://mcmc-jags.hg.sourceforge.net/hgweb/mcmc-jags/mcmc-jags/file/15af65a4be29/src/modules/bugs/distributions/DBetaBin.cc -- Joan Maspons CREAF (Centre de Recerca Ecològica i Aplicacions Forestals) Universitat Autònoma de Barcelona, 08193 Bellaterra (Barcelona), Catalonia Tel +34 93 581 2915 j.masp...@creaf.uab.cat http://www.creaf.uab.cat __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel -- Joan Maspons CREAF (Centre de Recerca Ecològica i Aplicacions Forestals) Universitat Autònoma de Barcelona, 08193 Bellaterra (Barcelona), Catalonia Tel +34 93 581 2915 j.masp...@creaf.uab.cat http://www.creaf.uab.cat [[alternative HTML version deleted]] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Patch to add Beta binomial distribution. Mentor needed!
it's already in the VGAM package http://www.stat.auckland.ac.nz/~yee/VGAM/ On Tue, May 22, 2012 at 7:59 AM, Joshua Ulrich josh.m.ulr...@gmail.comwrote: On Tue, May 22, 2012 at 8:27 AM, Joan Maspons j.masp...@creaf.uab.cat wrote: Hello, 2012/5/22 Christophe Dutang duta...@gmail.com Dear Joan, snip If you want to contribute to R, you should write a package and submit it to CRAN. See http://cran.r-project.org/doc/manuals/R-exts.html It's necessary to develop a package before to add the functions to R-base? I just want to add beta binomial and beta negative binomial distributions which from my point of view are not more strange than distributions included in R-base. I think they are quite common in order to simulate a binomial or negative binomial process in an stochastic environment. In order to add functions to the main R distribution, you have to convince someone on R-core to maintain the code. In the other hand I have no experience in writing packages so it would take me more time. The actuar package contains many additional distributions. You might see if the maintainer(s) would be interested in incorporating your code (if they don't have that functionality already). Yours, Joan Regards Christophe -- Christophe Dutang Ph.D. student at ISFA, Lyon, France website: http://dutangc.free.fr Le 22 mai 2012 à 12:14, Joan Maspons a écrit : Hello, I implemented the Beta binomial distribution following the patterns of the binomial distribution code and inspired by JAGS' code [1]. I have studied the code carefully but it's my first run in the R internals. Can somebody review the code and if everything it's ok commit to the repository? [1] http://mcmc-jags.hg.sourceforge.net/hgweb/mcmc-jags/mcmc-jags/file/15af65a4be29/src/modules/bugs/distributions/DBetaBin.cc -- Joan Maspons CREAF (Centre de Recerca Ecològica i Aplicacions Forestals) Universitat Autònoma de Barcelona, 08193 Bellaterra (Barcelona), Catalonia Tel +34 93 581 2915j.masp...@creaf.uab.cat http://www.creaf.uab.cat __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel -- Joan Maspons CREAF (Centre de Recerca Ecològica i Aplicacions Forestals) Universitat Autònoma de Barcelona, 08193 Bellaterra (Barcelona), Catalonia Tel +34 93 581 2915j.masp...@creaf.uab.cat http://www.creaf.uab.cat [[alternative HTML version deleted]] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel -- *A model is a lie that helps you see the truth.* * * Howard Skipperhttp://cancerres.aacrjournals.org/content/31/9/1173.full.pdf [[alternative HTML version deleted]] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] Codoc mismatch for roxygen-documented foo- functions
I have a roxygen2 documented package with functions for getting and setting an attribute. #' Get or set the foo attribute. #' #' Dummy function! #' #' @param x Object to hold the attribute. #' @param value Value to set the attribute to. #' @return The get function returns the foo attribute of \code{x}. #' @export foo - function(x) { attr(x, foo) } #' @rdname foo #' @export `foo-` - function(x, value) { attr(x, foo) - value } If I save the above to foo.R and then do library(roxygen2) library(devtools) package.skeleton(foo, code_files=foo.R) roxygenize(foo) check(foo) then the package checker gives me the warning Codoc mismatches from documentation object 'foo': foo- Code: function(x, value) Docs: function(x, value, value) How should I be documenting this sort of setter function? -- Regards, Richie live-analytics.com 4dpiecharts.com __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Patch to add Beta binomial distribution. Mentor needed!
Tim Triche, Jr. tim.triche at gmail.com writes: it's already in the VGAM package http://www.stat.auckland.ac.nz/~yee/VGAM/ [various snippage] also see library(sos) findFn(dbetabin*) and http://stackoverflow.com/questions/8065835/ proposing-feature-requests-to-the-r-core-team/8066062#8066062 [url broken] for some context on why you should build a package instead of trying to get a patch accepted in base R ... Ben Bolker On Tue, May 22, 2012 at 8:27 AM, Joan Maspons wrote: Hello, 2012/5/22 Christophe Dutang dutangc at gmail.com Dear Joan, snip If you want to contribute to R, you should write a package and submit it to CRAN. See http://cran.r-project.org/doc/manuals/R-exts.html It's necessary to develop a package before to add the functions to R-base? I just want to add beta binomial and beta negative binomial distributions which from my point of view are not more strange than distributions included in R-base. I think they are quite common in order to simulate a binomial or negative binomial process in an stochastic environment. In order to add functions to the main R distribution, you have to convince someone on R-core to maintain the code. __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] Best way to locate R executable from within R?
Hi, I'd like to spawn of a new R process from within R using system(), e.g. system(R -f myScript.R). However, just specifying R as in that example is not guaranteed to work, because R may not be on the OS's search path. What is the best way, from within a running R, to infer the command (basename or full path) for launching R in way that it works on any OS? I came up with the following alternatives, but I'm not sure if they'll work everywhere or not: 1. Rbin - commandArgs()[1]; 2. Rbin - file.path(R.home(), bin, R); Other suggestions that are better? /Henrik __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Best way to locate R executable from within R?
On Tue, May 22, 2012 at 10:34 AM, Henrik Bengtsson h...@biostat.ucsf.edu wrote: Hi, I'd like to spawn of a new R process from within R using system(), e.g. system(R -f myScript.R). However, just specifying R as in that example is not guaranteed to work, because R may not be on the OS's search path. What is the best way, from within a running R, to infer the command (basename or full path) for launching R in way that it works on any OS? I came up with the following alternatives, but I'm not sure if they'll work everywhere or not: 1. Rbin - commandArgs()[1]; 2. Rbin - file.path(R.home(), bin, R); Other suggestions that are better? Rbin - file.path(Sys.getenv(R_HOME), bin, R) Dan /Henrik __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Best way to locate R executable from within R?
On Tue, May 22, 2012 at 10:47 AM, Dan Tenenbaum dtene...@fhcrc.org wrote: On Tue, May 22, 2012 at 10:34 AM, Henrik Bengtsson h...@biostat.ucsf.edu wrote: Hi, I'd like to spawn of a new R process from within R using system(), e.g. system(R -f myScript.R). However, just specifying R as in that example is not guaranteed to work, because R may not be on the OS's search path. What is the best way, from within a running R, to infer the command (basename or full path) for launching R in way that it works on any OS? I came up with the following alternatives, but I'm not sure if they'll work everywhere or not: 1. Rbin - commandArgs()[1]; 2. Rbin - file.path(R.home(), bin, R); Other suggestions that are better? Rbin - file.path(Sys.getenv(R_HOME), bin, R) I don't see how Sys.getenv(R_HOME) would be better than R.home() - any reasons? Your reply triggered me to read up on help(R.home), where I noticed the passage: A character string giving the R home directory or path to a particular component. Normally the components are all subdirectories of the R home directory, but this may not be the case in a Unix-like installation. [...] The return value for modules and on Windows bin is to a sub-architecture-specific location. So, now I'd say that: 4. Rbin - file.path(R.home(bin), R); is better than (2). I'm still not sure whether to use (1) or (4), though. /Henrik Dan /Henrik __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Best way to locate R executable from within R?
On May 22, 2012, at 1:47 PM, Dan Tenenbaum dtene...@fhcrc.org wrote: On Tue, May 22, 2012 at 10:34 AM, Henrik Bengtsson h...@biostat.ucsf.edu wrote: Hi, I'd like to spawn of a new R process from within R using system(), e.g. system(R -f myScript.R). However, just specifying R as in that example is not guaranteed to work, because R may not be on the OS's search path. What is the best way, from within a running R, to infer the command (basename or full path) for launching R in way that it works on any OS? I came up with the following alternatives, but I'm not sure if they'll work everywhere or not: 1. Rbin - commandArgs()[1]; 2. Rbin - file.path(R.home(), bin, R); Other suggestions that are better? Rbin - file.path(Sys.getenv(R_HOME), bin, R) That is certainly worse, not better. 1. doesn't work because it may be a relative path. 2. Sounds pretty good - since the environment will be set by the current R. Dan /Henrik __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] bug in R version 2.15.0 (2012-03-30)?
On 5/19/12 12:22 AM, Wincent ronggui.hu...@gmail.com wrote: [SNIP] Also, is URI a typo of URL? No. It is not. http://www.w3.org/TR/uri-clarification/#uri-partitioning __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Best way to locate R executable from within R?
On Tue, May 22, 2012 at 1:34 PM, Henrik Bengtsson h...@biostat.ucsf.edu wrote: Hi, I'd like to spawn of a new R process from within R using system(), e.g. system(R -f myScript.R). However, just specifying R as in that example is not guaranteed to work, because R may not be on the OS's search path. What is the best way, from within a running R, to infer the command (basename or full path) for launching R in way that it works on any OS? I came up with the following alternatives, but I'm not sure if they'll work everywhere or not: 1. Rbin - commandArgs()[1]; 2. Rbin - file.path(R.home(), bin, R); Other suggestions that are better? At least on Windows one could run R via R.exe, Rterm.exe or Rgui.exe amd #2 would not pick up the differences. On the other hand if I do this on the Windows command line on my Vista system with R 2.15.0 patched: cd \program files\R\R-2.15.x\bin\i386 Rterm.exe and then enter commandArgs() into R, the output is Rterm.exe with no path. The fact that one can have 32 bit and 64 bit R executables on the same system complicates things too. Thus, on Windows something like this might work: file.path(R.home(bin), R.version$arch, basename(commandArgs()[[1]])) If there are cases that I missed then this might pick up those too: R - commandArgs()[[1]] if (R == basename(R)) R - file.path(R.home(bin), R.version$arch, R) -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Best way to locate R executable from within R?
On May 22, 2012, at 2:39 PM, Gabor Grothendieck ggrothendi...@gmail.com wrote: On Tue, May 22, 2012 at 1:34 PM, Henrik Bengtsson h...@biostat.ucsf.edu wrote: Hi, I'd like to spawn of a new R process from within R using system(), e.g. system(R -f myScript.R). However, just specifying R as in that example is not guaranteed to work, because R may not be on the OS's search path. What is the best way, from within a running R, to infer the command (basename or full path) for launching R in way that it works on any OS? I came up with the following alternatives, but I'm not sure if they'll work everywhere or not: 1. Rbin - commandArgs()[1]; 2. Rbin - file.path(R.home(), bin, R); Other suggestions that are better? At least on Windows one could run R via R.exe, Rterm.exe or Rgui.exe amd #2 would not pick up the differences. On the other hand if I do this on the Windows command line on my Vista system with R 2.15.0 patched: cd \program files\R\R-2.15.x\bin\i386 Rterm.exe and then enter commandArgs() into R, the output is Rterm.exe with no path. The fact that one can have 32 bit and 64 bit R executables on the same system complicates things too. Thus, on Windows something like this might work: file.path(R.home(bin), R.version$arch, basename(commandArgs()[[1]])) If there are cases that I missed then this might pick up those too: R - commandArgs()[[1]] if (R == basename(R)) R - file.path(R.home(bin), R.version$arch, R) Typically, when you want another subprocess of R it is not the same as the process you're in - e.g. you certainly don't want to use Rgui to run a script, so the above is not useful for Henrik's purpose. Besides, it won't even work since arg1 can as well be a symlink in a completely different place. Cheers, Simon -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Best way to locate R executable from within R?
On Tue, May 22, 2012 at 11:39 AM, Gabor Grothendieck ggrothendi...@gmail.com wrote: On Tue, May 22, 2012 at 1:34 PM, Henrik Bengtsson h...@biostat.ucsf.edu wrote: Hi, I'd like to spawn of a new R process from within R using system(), e.g. system(R -f myScript.R). However, just specifying R as in that example is not guaranteed to work, because R may not be on the OS's search path. What is the best way, from within a running R, to infer the command (basename or full path) for launching R in way that it works on any OS? I came up with the following alternatives, but I'm not sure if they'll work everywhere or not: 1. Rbin - commandArgs()[1]; 2. Rbin - file.path(R.home(), bin, R); Other suggestions that are better? At least on Windows one could run R via R.exe, Rterm.exe or Rgui.exe amd #2 would not pick up the differences. On the other hand if I do this on the Windows command line on my Vista system with R 2.15.0 patched: cd \program files\R\R-2.15.x\bin\i386 Rterm.exe and then enter commandArgs() into R, the output is Rterm.exe with no path. Thanks, I overlooked this need. For my particular use case, I'm interested in launching R in batch mode, so R will do (but not Rgui). The fact that one can have 32 bit and 64 bit R executables on the same system complicates things too. Thus, on Windows something like this might work: file.path(R.home(bin), R.version$arch, basename(commandArgs()[[1]])) If there are cases that I missed then this might pick up those too: R - commandArgs()[[1]] if (R == basename(R)) R - file.path(R.home(bin), R.version$arch, R) FYI, R.home(bin) is not the same as file.path(R.home(), bin), cf. help(R.home). R.home(bin) will pick up the current architecture directory (by using .Platform$r_arch), e.g. R.home(bin) [1] C:/PROGRA~1/R/R-2.15.0patched/bin/x64 /Henrik -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Best way to locate R executable from within R?
On Tue, May 22, 2012 at 3:05 PM, Henrik Bengtsson h...@biostat.ucsf.edu wrote: On Tue, May 22, 2012 at 11:39 AM, Gabor Grothendieck ggrothendi...@gmail.com wrote: On Tue, May 22, 2012 at 1:34 PM, Henrik Bengtsson h...@biostat.ucsf.edu wrote: Hi, I'd like to spawn of a new R process from within R using system(), e.g. system(R -f myScript.R). However, just specifying R as in that example is not guaranteed to work, because R may not be on the OS's search path. What is the best way, from within a running R, to infer the command (basename or full path) for launching R in way that it works on any OS? I came up with the following alternatives, but I'm not sure if they'll work everywhere or not: 1. Rbin - commandArgs()[1]; 2. Rbin - file.path(R.home(), bin, R); Other suggestions that are better? At least on Windows one could run R via R.exe, Rterm.exe or Rgui.exe amd #2 would not pick up the differences. On the other hand if I do this on the Windows command line on my Vista system with R 2.15.0 patched: cd \program files\R\R-2.15.x\bin\i386 Rterm.exe and then enter commandArgs() into R, the output is Rterm.exe with no path. Thanks, I overlooked this need. For my particular use case, I'm interested in launching R in batch mode, so R will do (but not Rgui). The fact that one can have 32 bit and 64 bit R executables on the same system complicates things too. Thus, on Windows something like this might work: file.path(R.home(bin), R.version$arch, basename(commandArgs()[[1]])) If there are cases that I missed then this might pick up those too: R - commandArgs()[[1]] if (R == basename(R)) R - file.path(R.home(bin), R.version$arch, R) FYI, R.home(bin) is not the same as file.path(R.home(), bin), cf. help(R.home). R.home(bin) will pick up the current architecture directory (by using .Platform$r_arch), e.g. R.home(bin) [1] C:/PROGRA~1/R/R-2.15.0patched/bin/x64 /Henrik Then perhaps something like this which is still not 100% foolproof but should work most of the time: Find(file.exists, c( commandArgs()[[1]], file.path(R.home(bin), commandArgs()[[1]]), file.path(R.home(bin), R) )) -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Best way to locate R executable from within R?
On Tue, May 22, 2012 at 3:28 PM, Gabor Grothendieck ggrothendi...@gmail.com wrote: On Tue, May 22, 2012 at 3:05 PM, Henrik Bengtsson h...@biostat.ucsf.edu wrote: On Tue, May 22, 2012 at 11:39 AM, Gabor Grothendieck ggrothendi...@gmail.com wrote: On Tue, May 22, 2012 at 1:34 PM, Henrik Bengtsson h...@biostat.ucsf.edu wrote: Hi, I'd like to spawn of a new R process from within R using system(), e.g. system(R -f myScript.R). However, just specifying R as in that example is not guaranteed to work, because R may not be on the OS's search path. What is the best way, from within a running R, to infer the command (basename or full path) for launching R in way that it works on any OS? I came up with the following alternatives, but I'm not sure if they'll work everywhere or not: 1. Rbin - commandArgs()[1]; 2. Rbin - file.path(R.home(), bin, R); Other suggestions that are better? At least on Windows one could run R via R.exe, Rterm.exe or Rgui.exe amd #2 would not pick up the differences. On the other hand if I do this on the Windows command line on my Vista system with R 2.15.0 patched: cd \program files\R\R-2.15.x\bin\i386 Rterm.exe and then enter commandArgs() into R, the output is Rterm.exe with no path. Thanks, I overlooked this need. For my particular use case, I'm interested in launching R in batch mode, so R will do (but not Rgui). The fact that one can have 32 bit and 64 bit R executables on the same system complicates things too. Thus, on Windows something like this might work: file.path(R.home(bin), R.version$arch, basename(commandArgs()[[1]])) If there are cases that I missed then this might pick up those too: R - commandArgs()[[1]] if (R == basename(R)) R - file.path(R.home(bin), R.version$arch, R) FYI, R.home(bin) is not the same as file.path(R.home(), bin), cf. help(R.home). R.home(bin) will pick up the current architecture directory (by using .Platform$r_arch), e.g. R.home(bin) [1] C:/PROGRA~1/R/R-2.15.0patched/bin/x64 /Henrik Then perhaps something like this which is still not 100% foolproof but should work most of the time: Find(file.exists, c( commandArgs()[[1]], file.path(R.home(bin), commandArgs()[[1]]), file.path(R.home(bin), R) )) So that the last one tried works on Windows too it should be: Find(file.exists, c( commandArgs()[[1]], file.path(R.home(bin), commandArgs()[[1]]), file.path(R.home(bin), R), file.path(R.home(bin), R.exe) )) -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] Capturing signals from within external libs
I have a continuous loop running in an external library that I am calling from C (R API). This loop is processing events in real time with the possibility of significant lag between events. When processing an event, I can make use of R_CheckUserInterrupt, but while the external library code is waiting on a new event, I don't have an opportunity to call this - my entry points are only on events. I can capture a SIGINT by redefining signal(SIGINT, myhandler) before calling the lib, but I am somewhat at a loss in terms of what I can do within the handler that would let me pass control back to R. void myhandler (int s) { error(interrupt caught!); } Works, but I am sure it isn't supposed to. In fact I know it is wrong, since after interrupting once SIGINTs are subsequently ignored, even if I reset the signal to the original one (as returned by the first call to signal). Currently I can exit(1) of course, but that is tragically bad form IMO, though will work in my situation. In short, what is the proper way to handle SIGINT in external code that is called from R, that allows R to handle the signal. Thoughts or suggestions appreciated. Thanks, Jeff __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Capturing signals from within external libs
Jeff, On May 22, 2012, at 4:31 PM, Jeffrey Ryan wrote: I have a continuous loop running in an external library that I am calling from C (R API). This loop is processing events in real time with the possibility of significant lag between events. When processing an event, I can make use of R_CheckUserInterrupt, but while the external library code is waiting on a new event, I don't have an opportunity to call this - my entry points are only on events. Assuming that while in the library there are no R calls (important!), you can use setjmp/longjmp to branch your code depending on whether you raise an interrupt or not (see below). This also makes sure that you process things on the R side properly Another alternative is to run your library call on a separate thread and have R wait for the result. In that case you don't need to mess with interrupts since your library code will run separately from R. The downside is that you need to mess with threads which may or may not be an issue depending on the complexity of your code and whether you want it to be cross-platform or not. Cheers, Simon Example code: #include signal.h #include setjmp.h #include unistd.h #include Rinternals.h #include R_ext/GraphicsEngine.h /* only needed if you use R_interrupts_pending */ static jmp_buf jenv; static void my_int(int sig) { longjmp(jenv, 1); /* this also restores the interrupt handlers */ } SEXP my_R_function(...) { if (setjmp(jenv) == 0) { /* enter your protected code */ void (*old_sig)(int); old_sig = signal(SIGINT, my_int); /* call your library here */ /* restore original INT handler */ signal(SIGINT, old_sig); } else { /* this will get called on interrupt */ /* you can do what you want - you're back to R-safe code here, so you can either raise an error or return from your function */ /* if you want to trigger regular R interrupt handling, use this: */ R_interrupts_pending = 1; R_CheckUserInterrupt(); /* the above should not return */ } I can capture a SIGINT by redefining signal(SIGINT, myhandler) before calling the lib, but I am somewhat at a loss in terms of what I can do within the handler that would let me pass control back to R. void myhandler (int s) { error(interrupt caught!); } Works, but I am sure it isn't supposed to. In fact I know it is wrong, since after interrupting once SIGINTs are subsequently ignored, even if I reset the signal to the original one (as returned by the first call to signal). Currently I can exit(1) of course, but that is tragically bad form IMO, though will work in my situation. In short, what is the proper way to handle SIGINT in external code that is called from R, that allows R to handle the signal. Thoughts or suggestions appreciated. Thanks, Jeff __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Best way to locate R executable from within R?
On May 22, 2012, at 3:34 PM, Gabor Grothendieck wrote: On Tue, May 22, 2012 at 3:28 PM, Gabor Grothendieck ggrothendi...@gmail.com wrote: On Tue, May 22, 2012 at 3:05 PM, Henrik Bengtsson h...@biostat.ucsf.edu wrote: On Tue, May 22, 2012 at 11:39 AM, Gabor Grothendieck ggrothendi...@gmail.com wrote: On Tue, May 22, 2012 at 1:34 PM, Henrik Bengtsson h...@biostat.ucsf.edu wrote: Hi, I'd like to spawn of a new R process from within R using system(), e.g. system(R -f myScript.R). However, just specifying R as in that example is not guaranteed to work, because R may not be on the OS's search path. What is the best way, from within a running R, to infer the command (basename or full path) for launching R in way that it works on any OS? I came up with the following alternatives, but I'm not sure if they'll work everywhere or not: 1. Rbin - commandArgs()[1]; 2. Rbin - file.path(R.home(), bin, R); Other suggestions that are better? At least on Windows one could run R via R.exe, Rterm.exe or Rgui.exe amd #2 would not pick up the differences. On the other hand if I do this on the Windows command line on my Vista system with R 2.15.0 patched: cd \program files\R\R-2.15.x\bin\i386 Rterm.exe and then enter commandArgs() into R, the output is Rterm.exe with no path. Thanks, I overlooked this need. For my particular use case, I'm interested in launching R in batch mode, so R will do (but not Rgui). The fact that one can have 32 bit and 64 bit R executables on the same system complicates things too. Thus, on Windows something like this might work: file.path(R.home(bin), R.version$arch, basename(commandArgs()[[1]])) If there are cases that I missed then this might pick up those too: R - commandArgs()[[1]] if (R == basename(R)) R - file.path(R.home(bin), R.version$arch, R) FYI, R.home(bin) is not the same as file.path(R.home(), bin), cf. help(R.home). R.home(bin) will pick up the current architecture directory (by using .Platform$r_arch), e.g. R.home(bin) [1] C:/PROGRA~1/R/R-2.15.0patched/bin/x64 /Henrik Then perhaps something like this which is still not 100% foolproof but should work most of the time: Find(file.exists, c( commandArgs()[[1]], file.path(R.home(bin), commandArgs()[[1]]), file.path(R.home(bin), R) )) So that the last one tried works on Windows too it should be: Find(file.exists, c( commandArgs()[[1]], file.path(R.home(bin), commandArgs()[[1]]), file.path(R.home(bin), R), file.path(R.home(bin), R.exe) )) Obviously, you don't want to do that for reasons discussed previously. -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Best way to locate R executable from within R?
I think the most reliable solution is something like system(paste(shQuote(file.path(R.home(bin),R)), ...)) it supports spaces in paths and works both on unix and Windows, picking the proper architecture. Cheers, Simon On May 22, 2012, at 3:05 PM, Henrik Bengtsson wrote: On Tue, May 22, 2012 at 11:39 AM, Gabor Grothendieck ggrothendi...@gmail.com wrote: On Tue, May 22, 2012 at 1:34 PM, Henrik Bengtsson h...@biostat.ucsf.edu wrote: Hi, I'd like to spawn of a new R process from within R using system(), e.g. system(R -f myScript.R). However, just specifying R as in that example is not guaranteed to work, because R may not be on the OS's search path. What is the best way, from within a running R, to infer the command (basename or full path) for launching R in way that it works on any OS? I came up with the following alternatives, but I'm not sure if they'll work everywhere or not: 1. Rbin - commandArgs()[1]; 2. Rbin - file.path(R.home(), bin, R); Other suggestions that are better? At least on Windows one could run R via R.exe, Rterm.exe or Rgui.exe amd #2 would not pick up the differences. On the other hand if I do this on the Windows command line on my Vista system with R 2.15.0 patched: cd \program files\R\R-2.15.x\bin\i386 Rterm.exe and then enter commandArgs() into R, the output is Rterm.exe with no path. Thanks, I overlooked this need. For my particular use case, I'm interested in launching R in batch mode, so R will do (but not Rgui). The fact that one can have 32 bit and 64 bit R executables on the same system complicates things too. Thus, on Windows something like this might work: file.path(R.home(bin), R.version$arch, basename(commandArgs()[[1]])) If there are cases that I missed then this might pick up those too: R - commandArgs()[[1]] if (R == basename(R)) R - file.path(R.home(bin), R.version$arch, R) FYI, R.home(bin) is not the same as file.path(R.home(), bin), cf. help(R.home). R.home(bin) will pick up the current architecture directory (by using .Platform$r_arch), e.g. R.home(bin) [1] C:/PROGRA~1/R/R-2.15.0patched/bin/x64 /Henrik -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Best way to locate R executable from within R?
On Tue, May 22, 2012 at 6:04 PM, Simon Urbanek simon.urba...@r-project.org wrote: On May 22, 2012, at 3:34 PM, Gabor Grothendieck wrote: On Tue, May 22, 2012 at 3:28 PM, Gabor Grothendieck ggrothendi...@gmail.com wrote: On Tue, May 22, 2012 at 3:05 PM, Henrik Bengtsson h...@biostat.ucsf.edu wrote: On Tue, May 22, 2012 at 11:39 AM, Gabor Grothendieck ggrothendi...@gmail.com wrote: On Tue, May 22, 2012 at 1:34 PM, Henrik Bengtsson h...@biostat.ucsf.edu wrote: Hi, I'd like to spawn of a new R process from within R using system(), e.g. system(R -f myScript.R). However, just specifying R as in that example is not guaranteed to work, because R may not be on the OS's search path. What is the best way, from within a running R, to infer the command (basename or full path) for launching R in way that it works on any OS? I came up with the following alternatives, but I'm not sure if they'll work everywhere or not: 1. Rbin - commandArgs()[1]; 2. Rbin - file.path(R.home(), bin, R); Other suggestions that are better? At least on Windows one could run R via R.exe, Rterm.exe or Rgui.exe amd #2 would not pick up the differences. On the other hand if I do this on the Windows command line on my Vista system with R 2.15.0 patched: cd \program files\R\R-2.15.x\bin\i386 Rterm.exe and then enter commandArgs() into R, the output is Rterm.exe with no path. Thanks, I overlooked this need. For my particular use case, I'm interested in launching R in batch mode, so R will do (but not Rgui). The fact that one can have 32 bit and 64 bit R executables on the same system complicates things too. Thus, on Windows something like this might work: file.path(R.home(bin), R.version$arch, basename(commandArgs()[[1]])) If there are cases that I missed then this might pick up those too: R - commandArgs()[[1]] if (R == basename(R)) R - file.path(R.home(bin), R.version$arch, R) FYI, R.home(bin) is not the same as file.path(R.home(), bin), cf. help(R.home). R.home(bin) will pick up the current architecture directory (by using .Platform$r_arch), e.g. R.home(bin) [1] C:/PROGRA~1/R/R-2.15.0patched/bin/x64 /Henrik Then perhaps something like this which is still not 100% foolproof but should work most of the time: Find(file.exists, c( commandArgs()[[1]], file.path(R.home(bin), commandArgs()[[1]]), file.path(R.home(bin), R) )) So that the last one tried works on Windows too it should be: Find(file.exists, c( commandArgs()[[1]], file.path(R.home(bin), commandArgs()[[1]]), file.path(R.home(bin), R), file.path(R.home(bin), R.exe) )) Obviously, you don't want to do that for reasons discussed previously. In most cases with a link the complete path would be passed in which case the first arg of Find would be chosen and be correct. If not it would fail through to further choices one of which would likely be correct and if none of them are then its likely that file.path(R.home(bin), R) isn't either since that is already one of the choices. While its not 100% foolproof the cases where it does not work are quite pathological whereas the cases where file.path(R.home(bin), R) fails to use the same executable include common cases such as R being called as Rterm or Rscript. -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Best way to locate R executable from within R?
On May 22, 2012, at 7:37 PM, Gabor Grothendieck wrote: On Tue, May 22, 2012 at 6:04 PM, Simon Urbanek simon.urba...@r-project.org wrote: On May 22, 2012, at 3:34 PM, Gabor Grothendieck wrote: On Tue, May 22, 2012 at 3:28 PM, Gabor Grothendieck ggrothendi...@gmail.com wrote: On Tue, May 22, 2012 at 3:05 PM, Henrik Bengtsson h...@biostat.ucsf.edu wrote: On Tue, May 22, 2012 at 11:39 AM, Gabor Grothendieck ggrothendi...@gmail.com wrote: On Tue, May 22, 2012 at 1:34 PM, Henrik Bengtsson h...@biostat.ucsf.edu wrote: Hi, I'd like to spawn of a new R process from within R using system(), e.g. system(R -f myScript.R). However, just specifying R as in that example is not guaranteed to work, because R may not be on the OS's search path. What is the best way, from within a running R, to infer the command (basename or full path) for launching R in way that it works on any OS? I came up with the following alternatives, but I'm not sure if they'll work everywhere or not: 1. Rbin - commandArgs()[1]; 2. Rbin - file.path(R.home(), bin, R); Other suggestions that are better? At least on Windows one could run R via R.exe, Rterm.exe or Rgui.exe amd #2 would not pick up the differences. On the other hand if I do this on the Windows command line on my Vista system with R 2.15.0 patched: cd \program files\R\R-2.15.x\bin\i386 Rterm.exe and then enter commandArgs() into R, the output is Rterm.exe with no path. Thanks, I overlooked this need. For my particular use case, I'm interested in launching R in batch mode, so R will do (but not Rgui). The fact that one can have 32 bit and 64 bit R executables on the same system complicates things too. Thus, on Windows something like this might work: file.path(R.home(bin), R.version$arch, basename(commandArgs()[[1]])) If there are cases that I missed then this might pick up those too: R - commandArgs()[[1]] if (R == basename(R)) R - file.path(R.home(bin), R.version$arch, R) FYI, R.home(bin) is not the same as file.path(R.home(), bin), cf. help(R.home). R.home(bin) will pick up the current architecture directory (by using .Platform$r_arch), e.g. R.home(bin) [1] C:/PROGRA~1/R/R-2.15.0patched/bin/x64 /Henrik Then perhaps something like this which is still not 100% foolproof but should work most of the time: Find(file.exists, c( commandArgs()[[1]], file.path(R.home(bin), commandArgs()[[1]]), file.path(R.home(bin), R) )) So that the last one tried works on Windows too it should be: Find(file.exists, c( commandArgs()[[1]], file.path(R.home(bin), commandArgs()[[1]]), file.path(R.home(bin), R), file.path(R.home(bin), R.exe) )) Obviously, you don't want to do that for reasons discussed previously. In most cases with a link the complete path would be passed in which case the first arg of Find would be chosen and be correct. If not it would fail through to further choices one of which would likely be correct and if none of them are then its likely that file.path(R.home(bin), R) isn't either since that is already one of the choices. While its not 100% foolproof the cases where it does not work are quite pathological whereas the cases where file.path(R.home(bin), R) fails to use the same executable include common cases such as R being called as Rterm or Rscript. Except that you may not have noticed that no one asked about that since that makes no sense (arguments differ etc.). The question was how to start R and your suggestions make it only worse and unusable - fortunately Henrik asked about better solutions so we can safely close this discussion. Cheers, Simon __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Best way to locate R executable from within R?
On Tue, May 22, 2012 at 7:50 PM, Simon Urbanek simon.urba...@r-project.org wrote: On May 22, 2012, at 7:37 PM, Gabor Grothendieck wrote: On Tue, May 22, 2012 at 6:04 PM, Simon Urbanek simon.urba...@r-project.org wrote: On May 22, 2012, at 3:34 PM, Gabor Grothendieck wrote: On Tue, May 22, 2012 at 3:28 PM, Gabor Grothendieck ggrothendi...@gmail.com wrote: On Tue, May 22, 2012 at 3:05 PM, Henrik Bengtsson h...@biostat.ucsf.edu wrote: On Tue, May 22, 2012 at 11:39 AM, Gabor Grothendieck ggrothendi...@gmail.com wrote: On Tue, May 22, 2012 at 1:34 PM, Henrik Bengtsson h...@biostat.ucsf.edu wrote: Hi, I'd like to spawn of a new R process from within R using system(), e.g. system(R -f myScript.R). However, just specifying R as in that example is not guaranteed to work, because R may not be on the OS's search path. What is the best way, from within a running R, to infer the command (basename or full path) for launching R in way that it works on any OS? I came up with the following alternatives, but I'm not sure if they'll work everywhere or not: 1. Rbin - commandArgs()[1]; 2. Rbin - file.path(R.home(), bin, R); Other suggestions that are better? At least on Windows one could run R via R.exe, Rterm.exe or Rgui.exe amd #2 would not pick up the differences. On the other hand if I do this on the Windows command line on my Vista system with R 2.15.0 patched: cd \program files\R\R-2.15.x\bin\i386 Rterm.exe and then enter commandArgs() into R, the output is Rterm.exe with no path. Thanks, I overlooked this need. For my particular use case, I'm interested in launching R in batch mode, so R will do (but not Rgui). The fact that one can have 32 bit and 64 bit R executables on the same system complicates things too. Thus, on Windows something like this might work: file.path(R.home(bin), R.version$arch, basename(commandArgs()[[1]])) If there are cases that I missed then this might pick up those too: R - commandArgs()[[1]] if (R == basename(R)) R - file.path(R.home(bin), R.version$arch, R) FYI, R.home(bin) is not the same as file.path(R.home(), bin), cf. help(R.home). R.home(bin) will pick up the current architecture directory (by using .Platform$r_arch), e.g. R.home(bin) [1] C:/PROGRA~1/R/R-2.15.0patched/bin/x64 /Henrik Then perhaps something like this which is still not 100% foolproof but should work most of the time: Find(file.exists, c( commandArgs()[[1]], file.path(R.home(bin), commandArgs()[[1]]), file.path(R.home(bin), R) )) So that the last one tried works on Windows too it should be: Find(file.exists, c( commandArgs()[[1]], file.path(R.home(bin), commandArgs()[[1]]), file.path(R.home(bin), R), file.path(R.home(bin), R.exe) )) Obviously, you don't want to do that for reasons discussed previously. In most cases with a link the complete path would be passed in which case the first arg of Find would be chosen and be correct. If not it would fail through to further choices one of which would likely be correct and if none of them are then its likely that file.path(R.home(bin), R) isn't either since that is already one of the choices. While its not 100% foolproof the cases where it does not work are quite pathological whereas the cases where file.path(R.home(bin), R) fails to use the same executable include common cases such as R being called as Rterm or Rscript. Except that you may not have noticed that no one asked about that since that makes no sense (arguments differ etc.). The question was how to start R and your suggestions make it only worse and unusable - fortunately Henrik asked about better solutions so we can safely close this discussion. Cheers, Simon So far he has excluded Rgui but that still leaves Rterm, Rscript and R (and littler on UNIX) -- all of which are valid ways to launch R. If its sufficient to always launch it as R then your solution is briefer but it is subsumed in the one I posted which handles it in full generality. Its really a matter of usage case at this point. -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel