[Rd] How I() works in a formula
Dear all, I'm updating a package regarding a new type of models, and I'm looking to extend the formula interface with two functions (L() and R() ) for construction of these models. I want to use as much of the formula interface as possible, and hoped to do something similarly to I(). I know the I() function does nothing more than add the class "AsIs". I've been browsing the source code of R for a couple of days now trying to locate where this class assignment gets translated into a specific action, but i couldn't locate it. I've been as far as the internal C function modelframe. Any pointers on how I() is processed internally are greatly appreciated. Cheers Joris -- Joris Meys Statistical consultant Ghent University Faculty of Bioscience Engineering Department of Mathematical Modelling, Statistics and Bio-Informatics tel : +32 9 264 59 87 joris.m...@ugent.be --- Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php [[alternative HTML version deleted]] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] How I() works in a formula
On 03 Oct 2014, at 14:32 , Joris Meys wrote: > Dear all, > > I'm updating a package regarding a new type of models, and I'm looking to > extend the formula interface with two functions (L() and R() ) for > construction of these models. I want to use as much of the formula > interface as possible, and hoped to do something similarly to I(). > > I know the I() function does nothing more than add the class "AsIs". I've > been browsing the source code of R for a couple of days now trying to > locate where this class assignment gets translated into a specific action, > but i couldn't locate it. I've been as far as the internal C function > modelframe. > > Any pointers on how I() is processed internally are greatly appreciated. It isn't... > E <- function(x)x > x <- rnorm(10) > y <- rnorm(10) > lm(y~x+E(x^2)) Call: lm(formula = y ~ x + E(x^2)) Coefficients: (Intercept)x E(x^2) 0.2757 0.1725 -0.3823 The point is that special interpretation of operators never happens inside function calls. I() is just a convenient do-nothing function call. If you want to add special operators, one place to look is in the handling of specials for survival::coxph. > > Cheers > Joris > > -- > Joris Meys > Statistical consultant > > Ghent University > Faculty of Bioscience Engineering > Department of Mathematical Modelling, Statistics and Bio-Informatics > > tel : +32 9 264 59 87 > joris.m...@ugent.be > --- > Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php > > [[alternative HTML version deleted]] > > __ > R-devel@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel -- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd@cbs.dk Priv: pda...@gmail.com __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] How I() works in a formula
Joris, Basically, the I() function, as it is used in a regression model, allows the user to perform arithmetic operations on a variable that would otherwise be interpreted by the formula. It is not trapped as a special function as Error() is in aov(). There may be other applications where the class "AsIs" is needed, so there are support functions for subscripting, formatting, printing and so forth. Dave On Fri, Oct 3, 2014 at 7:32 AM, Joris Meys wrote: > Dear all, > > I'm updating a package regarding a new type of models, and I'm looking to > extend the formula interface with two functions (L() and R() ) for > construction of these models. I want to use as much of the formula > interface as possible, and hoped to do something similarly to I(). > > I know the I() function does nothing more than add the class "AsIs". I've > been browsing the source code of R for a couple of days now trying to > locate where this class assignment gets translated into a specific action, > but i couldn't locate it. I've been as far as the internal C function > modelframe. > > Any pointers on how I() is processed internally are greatly appreciated. > > Cheers > Joris > > -- > Joris Meys > Statistical consultant > > Ghent University > Faculty of Bioscience Engineering > Department of Mathematical Modelling, Statistics and Bio-Informatics > > tel : +32 9 264 59 87 > joris.m...@ugent.be > --- > Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php > > [[alternative HTML version deleted]] > > __ > R-devel@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel > [[alternative HTML version deleted]] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] How I() works in a formula
Thanks Peter! That clarifies why it felt I was chasing ghosts these past days :) Thanks for the tip about coxph as well, there's some nice ideas to be discovered there. Cheers Joris On Fri, Oct 3, 2014 at 3:02 PM, peter dalgaard wrote: > > On 03 Oct 2014, at 14:32 , Joris Meys wrote: > > > Dear all, > > > > I'm updating a package regarding a new type of models, and I'm looking to > > extend the formula interface with two functions (L() and R() ) for > > construction of these models. I want to use as much of the formula > > interface as possible, and hoped to do something similarly to I(). > > > > I know the I() function does nothing more than add the class "AsIs". I've > > been browsing the source code of R for a couple of days now trying to > > locate where this class assignment gets translated into a specific > action, > > but i couldn't locate it. I've been as far as the internal C function > > modelframe. > > > > Any pointers on how I() is processed internally are greatly appreciated. > > It isn't... > > > E <- function(x)x > > x <- rnorm(10) > > y <- rnorm(10) > > lm(y~x+E(x^2)) > > Call: > lm(formula = y ~ x + E(x^2)) > > Coefficients: > (Intercept)x E(x^2) > 0.2757 0.1725 -0.3823 > > > The point is that special interpretation of operators never happens inside > function calls. I() is just a convenient do-nothing function call. > > If you want to add special operators, one place to look is in the handling > of specials for survival::coxph. > > > > > > Cheers > > Joris > > > > -- > > Joris Meys > > Statistical consultant > > > > Ghent University > > Faculty of Bioscience Engineering > > Department of Mathematical Modelling, Statistics and Bio-Informatics > > > > tel : +32 9 264 59 87 > > joris.m...@ugent.be > > --- > > Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php > > > > [[alternative HTML version deleted]] > > > > __ > > R-devel@r-project.org mailing list > > https://stat.ethz.ch/mailman/listinfo/r-devel > > -- > Peter Dalgaard, Professor, > Center for Statistics, Copenhagen Business School > Solbjerg Plads 3, 2000 Frederiksberg, Denmark > Phone: (+45)38153501 > Email: pd@cbs.dk Priv: pda...@gmail.com > > > > > > > > > -- Joris Meys Statistical consultant Ghent University Faculty of Bioscience Engineering Department of Mathematical Modelling, Statistics and Bio-Informatics tel : +32 9 264 59 87 joris.m...@ugent.be --- Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php [[alternative HTML version deleted]] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Intel Fortran compiler returns a -1 TRUE value
On Thu, Oct 2, 2014 at 4:25 PM, Ei-ji Nakama wrote: > Hello > > > The value generated by Fortran's .TRUE. evaluates as "truthy" -- as in > > all(z[[1]]) -- but is neither equal to nor identical to TRUE. Its numeric > > conversion to -1 is most unusual, every other system I've tried converts > to > > +1. > > Please read the -fpscomp logicals option of ifort. > Wow that's an interesting read, and the line "Intel recommends that you avoid coding practices that depend on the internal representation of LOGICAL values" says it all with regard to R and Fortran LOGICALS, I think! Barry [[alternative HTML version deleted]] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] Any penalty for using gzfile() in place of file() for reading?
A question I meant to ask for a very long time: I have several functions that temporarily open files using file(..., open="rb"). I'd like to support gzip'ed files also and noticed that gzfile(..., open="rb") handles also non-compressed files, cf. help("gzfile"): For 'gzfile' the description is the path to a file compressed by 'gzip': it can also open for reading uncompressed files and those compressed by 'bzip2', 'xz' or 'lzma'. >From simple benchmarking I cannot measure any overhead from using gzfile(). I assume the only overhead would come from inspecting the first few bytes in the file. Also, there is no risk that my non-compressed files have gzip header (by chance), so that is not a concern. Does anyone see a reason for not just using gzfile(..., open="rb") everywhere I use file(..., open="rb") today? /Henrik __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] mpi.h errors on Mavericks packages
Dear mac folks, I have started porting a large legacy toolset maintained in windows and heavily mpi laden so it can be used across platforms in R... so I am building a package out of it. On this note, I am noticing that almost all of the mpi dependent packages do not compile on the CRAN repositories with the basic issue that it appears it can not find mpi installed: configure: error: "Cannot find mpi.h header file" I do not see any chatter about mpi issues in the lists since the inception of mavericks.. and possibly this question should go to Simon.. but in case I missed a discussion, or if anyone has any suggestions on how to proceed, or what might be missing from the Rmpi, npRmpi, etc. packages for compilation on Mavericks, it would be greatly appreciated if you could let me know.. and maybe I can help fix the other packages as well. Thanks for any help or pointers to guide me! dan __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] mpi.h errors on Mavericks packages
On 10/03/2014 04:17 PM, Daniel Fuka wrote: Dear mac folks, I have started porting a large legacy toolset maintained in windows and heavily mpi laden so it can be used across platforms in R... so I am building a package out of it. On this note, I am noticing that almost all of the mpi dependent packages do not compile on the CRAN repositories with the basic issue that it appears it can not find mpi installed: configure: error: "Cannot find mpi.h header file" Hi Dan -- not a mac folk, or particularly expert on the subject, but have you looked at section 1.2.1.1 of RShowDoc("R-exts")? The basic idea is a) check for compiler support via a src/Makevars file that might be like PKG_CFLAGS = $(SHLIB_OPENMP_CFLAGS) PKG_LIBS = $(SHLIB_OPENMP_CFLAGS) b) conditionally include mpi header files and execute mpi code with #ifdef SUPPORT_OPENMP #include #endif and similarly for #pragma's and other mpi-isms littered through your code? Likely this gets quite tedious for projects making extensive use of openMP. Martin I do not see any chatter about mpi issues in the lists since the inception of mavericks.. and possibly this question should go to Simon.. but in case I missed a discussion, or if anyone has any suggestions on how to proceed, or what might be missing from the Rmpi, npRmpi, etc. packages for compilation on Mavericks, it would be greatly appreciated if you could let me know.. and maybe I can help fix the other packages as well. Thanks for any help or pointers to guide me! dan __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel -- Computational Biology / Fred Hutchinson Cancer Research Center 1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109 Location: Arnold Building M1 B861 Phone: (206) 667-2793 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] mpi.h errors on Mavericks packages
On 10/03/2014 04:58 PM, Martin Morgan wrote: On 10/03/2014 04:17 PM, Daniel Fuka wrote: Dear mac folks, I have started porting a large legacy toolset maintained in windows and heavily mpi laden so it can be used across platforms in R... so I am building a package out of it. On this note, I am noticing that almost all of the mpi dependent packages do not compile on the CRAN repositories with the basic issue that it appears it can not find mpi installed: configure: error: "Cannot find mpi.h header file" sorry for the noise! you're after mpi and not openMP. Arrgh Martin Hi Dan -- not a mac folk, or particularly expert on the subject, but have you looked at section 1.2.1.1 of RShowDoc("R-exts")? The basic idea is a) check for compiler support via a src/Makevars file that might be like PKG_CFLAGS = $(SHLIB_OPENMP_CFLAGS) PKG_LIBS = $(SHLIB_OPENMP_CFLAGS) b) conditionally include mpi header files and execute mpi code with #ifdef SUPPORT_OPENMP #include #endif and similarly for #pragma's and other mpi-isms littered through your code? Likely this gets quite tedious for projects making extensive use of openMP. Martin I do not see any chatter about mpi issues in the lists since the inception of mavericks.. and possibly this question should go to Simon.. but in case I missed a discussion, or if anyone has any suggestions on how to proceed, or what might be missing from the Rmpi, npRmpi, etc. packages for compilation on Mavericks, it would be greatly appreciated if you could let me know.. and maybe I can help fix the other packages as well. Thanks for any help or pointers to guide me! dan __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel -- Computational Biology / Fred Hutchinson Cancer Research Center 1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109 Location: Arnold Building M1 B861 Phone: (206) 667-2793 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] mpi.h errors on Mavericks packages
Daniel, On Oct 3, 2014, at 7:17 PM, Daniel Fuka wrote: > Dear mac folks, > > I have started porting a large legacy toolset maintained in windows > and heavily mpi laden so it can be used across platforms in R... so I > am building a package out of it. On this note, I am noticing that > almost all of the mpi dependent packages do not compile on the CRAN > repositories with the basic issue that it appears it can not find > mpi installed: > > configure: error: "Cannot find mpi.h header file" > > I do not see any chatter about mpi issues in the lists since the > inception of mavericks.. and possibly this question should go to > Simon.. but in case I missed a discussion, or if anyone has any > suggestions on how to proceed, or what might be missing from the Rmpi, > npRmpi, etc. packages for compilation on Mavericks, it would be > greatly appreciated if you could let me know.. and maybe I can help > fix the other packages as well. Apple has removed MPI from recent OS X versions so it is not available there. So currently, you have to install whatever MPI implementation you prefer from sources since neither the libraries nor the toolchain are available. What Apple used to ship was OpenMPI which still exists, but to my best knowledge there is no official, maintained binary for OS X so on Mavericks we have nothing to build CRAN binaries against, so you have to install everything from sources. Cheers, Simon __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] mpi.h errors on Mavericks packages
FYI https://groups.google.com/forum/#!topic/rbigdataprogramming/k1uZWmzd1L8 or FAQ, Section 8.3, question 10 at https://github.com/snoweye/pbdMPI/blob/master/inst/doc/pbdMPI-guide.pdf?raw=true may be useful. On Fri, Oct 3, 2014 at 9:10 PM, Simon Urbanek wrote: > Daniel, > > On Oct 3, 2014, at 7:17 PM, Daniel Fuka wrote: > > > Dear mac folks, > > > > I have started porting a large legacy toolset maintained in windows > > and heavily mpi laden so it can be used across platforms in R... so I > > am building a package out of it. On this note, I am noticing that > > almost all of the mpi dependent packages do not compile on the CRAN > > repositories with the basic issue that it appears it can not find > > mpi installed: > > > > configure: error: "Cannot find mpi.h header file" > > > > I do not see any chatter about mpi issues in the lists since the > > inception of mavericks.. and possibly this question should go to > > Simon.. but in case I missed a discussion, or if anyone has any > > suggestions on how to proceed, or what might be missing from the Rmpi, > > npRmpi, etc. packages for compilation on Mavericks, it would be > > greatly appreciated if you could let me know.. and maybe I can help > > fix the other packages as well. > > > Apple has removed MPI from recent OS X versions so it is not available > there. > > So currently, you have to install whatever MPI implementation you prefer > from sources since neither the libraries nor the toolchain are available. > What Apple used to ship was OpenMPI which still exists, but to my best > knowledge there is no official, maintained binary for OS X so on Mavericks > we have nothing to build CRAN binaries against, so you have to install > everything from sources. > > Cheers, > Simon > > __ > R-devel@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel > [[alternative HTML version deleted]] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel