[Rd] Portability of a C function
Hi the list, In a package P1, I write a function f1 in C, potentially an internal function (not to be called from R). In a package P2, I write a function f2 in C. The f2 function needs to use f1 from P1. Is it possible ? --- 8< In file P1.c - double f1(x,y){ } --- 8< In file P2.c - void f2(x,y,z){ double result; result = f1(x,y); } Thanks Christophe __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Portability of a C function
Hello, This was discussed this week in the thread "LinkingTo and C++". It is possible, and documented in WRE section 5.4 : http://cran.r-project.org/doc/manuals/R-exts.html#Registering-native-routines Romain On 02/14/2010 12:58 PM, Christophe Genolini wrote: Hi the list, In a package P1, I write a function f1 in C, potentially an internal function (not to be called from R). In a package P2, I write a function f2 in C. The f2 function needs to use f1 from P1. Is it possible ? --- 8< In file P1.c - double f1(x,y){ } --- 8< In file P2.c - void f2(x,y,z){ double result; result = f1(x,y); } Thanks Christophe -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://tr.im/O1wO : highlight 0.1-5 |- http://tr.im/O1qJ : Rcpp 0.7.6 `- http://tr.im/NrTG : Rcpp 0.7.5 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Portability of a C function
On 14 February 2010 at 12:58, Christophe Genolini wrote: | Hi the list, | | In a package P1, I write a function f1 in C, potentially an internal | function (not to be called from R). | In a package P2, I write a function f2 in C. The f2 function needs to | use f1 from P1. Is it possible ? Yes. See 'Writing R Extension' on LinkingTo. You can register f1 for use by the others, if P2 has a LinkingTo: on P1 then you're good. The 'classic' example is for lme4 using (large) parts of Matrix. Dirk | --- 8< In file P1.c - | double f1(x,y){ | | } | | --- 8< In file P2.c - | void f2(x,y,z){ |double result; | |result = f1(x,y); | | } | | Thanks | Christophe | | __ | R-devel@r-project.org mailing list | https://stat.ethz.ch/mailman/listinfo/r-devel -- Registration is open for the 2nd International conference R / Finance 2010 See http://www.RinFinance.com for details, and see you in Chicago in April! __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] Feature Request: Multiline Comments
Hello, Is it possible to extend the R lexer/parser to include multiline comments like /* acomment */ ? This way I can integrate emacs org-mode with my R code, so that I can have a table of contents, section folding, html-output of source etc. e.g /* * Display Code */ #+BEGIN_SRC R foo <- function(...){ stuff } #+end_src and so on . Thanks Saptarshi __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] How S3method() is implemented and called? And when to use it?
R-exts.pdf discribes S3method a little bit. But I want to understand more on how it is called, implemented and when to use it. I don't find it in an R session. But I see S3method() in some NAMESPACE files. > S3method Error: object 'S3method' not found > ?S3method No documentation for 'S3method' in specified packages and libraries: you could try '??S3method' I don't understand why S3method is necessary. My understanding is that we can always use print.foo(} # and appropriate exporting to replace S3method(print, foo) , right? Or I misunderstand something? __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] How S3method() is implemented and called? And when to use it?
Hello `Blue Sky` , Will you please start posting under your real name. As documented in WRE, S3method is meant for use in namespaces: http://cran.r-project.org/doc/manuals/R-exts.html#Registering-S3-methods It is not an R function. Romain On 02/14/2010 07:32 PM, blue sky wrote: R-exts.pdf discribes S3method a little bit. But I want to understand more on how it is called, implemented and when to use it. I don't find it in an R session. But I see S3method() in some NAMESPACE files. S3method Error: object 'S3method' not found ?S3method No documentation for 'S3method' in specified packages and libraries: you could try '??S3method' I don't understand why S3method is necessary. My understanding is that we can always use print.foo(} # and appropriate exporting to replace S3method(print, foo) , right? Or I misunderstand something? -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://tr.im/O1wO : highlight 0.1-5 |- http://tr.im/O1qJ : Rcpp 0.7.6 `- http://tr.im/NrTG : Rcpp 0.7.5 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] R CMD INSTALL customization; followup on Dirk's question
Last year, Dirk E was asking about customizing options to for packages when using R CMD INSTALL http://tolstoy.newcastle.edu.au/R/e4/devel/08/06/1980.html Has there been more on that question lately? I also wonder what this means in the "Building Packages" section of the R-Extensions manual: "R CMD build can also build pre-compiled version of packages for binary distributions, but R CMD INSTALL --build is preferred (and is considerably more flexible). " For an RPM-based Linux system, what are the possibilities for "binary packages" in that sentence? Here's why I ask. I have to install R packages on each system in a cluster. I would like to build RPM packages for R packages and drop them into the automatic updating system. For some R packages, there are existing RPM packages in the Fedora repos, but the list is not exhaustive. I do not want to spend my life fiddling R spec files package-by-package, I just want to try to run the R CMD INSTALL lots of times, and if a package builds then package them up. Most packages do work without customization, after all. If a package fails, I can always look into it later and customize the build for it, but I don't want to take the "boutique" approach implicit in existing packaging efforts for RPMs (such as R2spec). I admire what Dirk did with cran2deb and if I had a research assistant, I'd imitate that approach to make automatic RPMS for all R packages and customize steps for packages that fail. Did you ever use "checkinstall"? It is a way to 'cheat' while making RPM packages. If you ordinarily do "configure" "make" "make install", checkinstall It is used in place of "make install". It can just create the binary package from the installed files, without requiring a lot of fiddling about. Sure, its cheating, but even Captain Kirk cheated when he needed to pass the Starfleet exam :). Checkinstall can take command line options for all the usual details that would go into a spec file. So, could I figure a way to embed "checkinstall" into the middle of the process that goes on in R CMD INSTALL ?? -- Paul E. Johnson Professor, Political Science 1541 Lilac Lane, Room 504 University of Kansas __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Portability of a C function
Thanks, this helps a lot. So if I understand correctly: in package P1, I want to export printMatrix and printMatrixInt. In my file P1.c, I have to add void R_init_P1(DllInfo *info){ R_registerCCallable("longitudinalData","printMatrix",printMatrix); R_registerCCallable("longitudinalData","printMatrixInt",printMatrixInt); }; In P2.c, I have to add : void R_init_P2(DllInfo *info){ printMatrix = R_GetCCallable("longitudinalData","printMatrix"); printMatrixInt = R_GetCCallable("longitudinalData","printMatrixInt"); }; I still have a problem here: "Writing R ext" say that 'printMatrix' and 'printMatrixInt' should have "an appropriate declaration". What is the appropriate declaration? Christophe Hello, This was discussed this week in the thread "LinkingTo and C++". It is possible, and documented in WRE section 5.4 : http://cran.r-project.org/doc/manuals/R-exts.html#Registering-native-routines Romain On 02/14/2010 12:58 PM, Christophe Genolini wrote: Hi the list, In a package P1, I write a function f1 in C, potentially an internal function (not to be called from R). In a package P2, I write a function f2 in C. The f2 function needs to use f1 from P1. Is it possible ? --- 8< In file P1.c - double f1(x,y){ } --- 8< In file P2.c - void f2(x,y,z){ double result; result = f1(x,y); } Thanks Christophe __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Portability of a C function
Take a look here, as this may help clear up the unanswered questions: https://stat.ethz.ch/pipermail/r-devel/2008-November/051262.html HTH Jeff Jeffrey A. Ryan jeffrey.r...@insightalgo.com ia: insight algorithmics www.insightalgo.com On Feb 14, 2010, at 3:18 PM, Christophe Genolini paris10.fr> wrote: Thanks, this helps a lot. So if I understand correctly: in package P1, I want to export printMatrix and printMatrixInt. In my file P1.c, I have to add void R_init_P1(DllInfo *info){ R_registerCCallable("longitudinalData","printMatrix",printMatrix); R_registerCCallable ("longitudinalData","printMatrixInt",printMatrixInt); }; In P2.c, I have to add : void R_init_P2(DllInfo *info){ printMatrix = R_GetCCallable("longitudinalData","printMatrix"); printMatrixInt = R_GetCCallable ("longitudinalData","printMatrixInt"); }; I still have a problem here: "Writing R ext" say that 'printMatrix' and 'printMatrixInt' should have "an appropriate declaration". What is the appropriate declaration? Christophe Hello, This was discussed this week in the thread "LinkingTo and C++". It is possible, and documented in WRE section 5.4 : http://cran.r-project.org/doc/manuals/R-exts.html#Registering-native-routines Romain On 02/14/2010 12:58 PM, Christophe Genolini wrote: Hi the list, In a package P1, I write a function f1 in C, potentially an internal function (not to be called from R). In a package P2, I write a function f2 in C. The f2 function needs to use f1 from P1. Is it possible ? --- 8< In file P1.c - double f1(x,y){ } --- 8< In file P2.c - void f2(x,y,z){ double result; result = f1(x,y); } Thanks Christophe __ 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] Feature Request: Multiline Comments
Saptarshi Guha gmail.com> writes: > > Hello, > Is it possible to extend the R lexer/parser to include multiline comments like > /* > acomment > > */ > ? > This way I can integrate emacs org-mode with my R code, so that I can > have a table of contents, > section folding, html-output of source etc. > This comes up from time to time, and the typical answer is "no, it's not that easy, block-commenting and -uncommenting is easy in any code editor (including Emacs). However, there are a number of R/Emacs/ESS gurus on this list, and maybe someone will answer your more general "is there a way to integrate org-mode with my R code" question ... http://finzi.psych.upenn.edu/R/Rhelp02/archive/91555.html > e.g > /* > * Display Code > */ > #+BEGIN_SRC R > > foo <- function(...){ > stuff > } > > #+end_src > > and so on . > > Thanks > Saptarshi > > __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] org-mode (was Re: Feature Request: Multiline Comments)
On 02/14/2010 08:11 AM, Saptarshi Guha wrote: > Hello, > Is it possible to extend the R lexer/parser to include multiline comments like > /* > acomment > > */ > ? > This way I can integrate emacs org-mode with my R code, so that I can > have a table of contents, > section folding, html-output of source etc. Hi Saptarshi -- Do you know about http://orgmode.org/worg/org-tutorials/org-R/org-R.php ? Martin > > e.g > /* > * Display Code > */ > #+BEGIN_SRC R > > foo <- function(...){ > stuff > } > > #+end_src > > and so on . > > Thanks > Saptarshi > > __ > R-devel@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel -- Martin Morgan 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] org-mode (was Re: Feature Request: Multiline Comments)
Martin Morgan wrote: On 02/14/2010 08:11 AM, Saptarshi Guha wrote: Hello, Is it possible to extend the R lexer/parser to include multiline comments like /* acomment */ ? This way I can integrate emacs org-mode with my R code, so that I can have a table of contents, section folding, html-output of source etc. Hi Saptarshi -- Do you know about http://orgmode.org/worg/org-tutorials/org-R/org-R.php ? And also the very excellent org-babel, which can be used with R! http://orgmode.org/worg/org-contrib/babel/index.php __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Incorrect Kendall's tau for ordered variables (PR#14207)
What seems a more serious error is that the current code (and Peter's modification) returns correlations computed from unordered factors, and there are examples in packages 'agsemisc', 'ggm' and 'mi'. And in all cases these are Pearson correlations, as is the use of ordered factors in 'sfsmisc'. The as.vector() seems to have been introduced to combat PR#7116, but it is not the right fix as swapping the 'x' and 'y' arguments in the regression example for that still crashed. (It seems to me that the correct C-level fix is to check the length of the dimnames before trying to access the second element.) It would be tricky to do the coercion right for ordered factors (or more general rankable classes): cor() accepts a data frame and does as.matrix() on it: if the data frame includes such columns the coercion has to be done column-by-column. So I decided to pass the responsibility back to the caller, and only accept numeric arguments (as the help page says). However, package 'mice' passes a logical matrix, and as we do usually silently promote logical to numeric I have continued to allow that. Experience suggests that we have been too generous in doing autmatic coercion in the past. It seems every time we tighten something up we find a handful of packages that got dubious results from inappropriate conversions. On Mon, 8 Feb 2010, Prof Brian Ripley wrote: On Mon, 8 Feb 2010, Peter Dalgaard wrote: m...@biostat.mgh.harvard.edu wrote: Full_Name: Marek Ancukiewicz Version: 2.10.1 OS: Linux Submission from: (NULL) (74.0.49.2) Both cor() and cor.test() incorrectly handle ordered variables with method="kendall", cor() incorrectly handles ordered variables for method="spearman" (method="person" always works correctly, while method="spearman" works for cor.test, but not for cor()). In erroneous calculations these functions ignore the inherent ordering of the ordered variable (e.g., '9'<'10'<'11') and instead seem to assume an alphabetic ordering ('10'<'11'<'9'). Strictly speaking, not a bug, since the documentation has x: a numeric vector, matrix or data frame. respectively x, y: numeric vectors of data values. ‘x’ and ‘y’ must have the same length. so noone ever claimed that class "ordered" variables should work. However, the root cause is that as.vector on a factor variable (ordered or not) converts it to a character vector, hence rank(as.vector(as.ordered(9:11))) [1] 3 1 2 Looks like a simple fix would be to use as.vector(x, "numeric") inside the definition of cor(). A fix for that particular case: the problem is that relies on the underlying representation. I think a better fix would be to do either of - test for numeric and throw an error otherwise, or - use xtfrm, which has the advantage of being more general and allowing methods to be written (S3 or S4 methods in R-devel). cor(9:11,1:3,method="k") [1] 1 cor(as.ordered(9:11),1:3,method="k") [1] -0.333 cor.test(as.ordered(9:11),1:3,method="k") Kendall's rank correlation tau data: as.ordered(9:11) and 1:3 T = 1, p-value = 1 alternative hypothesis: true tau is not equal to 0 sample estimates: tau -0.333 cor(9:11,1:3,method="s") [1] 1 cor(as.ordered(9:11),1:3,method="s") [1] -0.5 cor.test(as.ordered(9:11),1:3,method="s") Spearman's rank correlation rho data: as.ordered(9:11) and 1:3 S = 0, p-value = 0. alternative hypothesis: true rho is not equal to 0 sample estimates: rho 1 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel -- O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - (p.dalga...@biostat.ku.dk) FAX: (+45) 35327907 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel -- 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 -- 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-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel