[Rd] access to R parse tree for Lisp-style macros?
R folks, I'm curious about possible support for Lisp-style macros in R. I'm aware of the "defmacro" support for S-Plus and R discussed here: http://www.biostat.wustl.edu/archives/html/s-news/2002-10/msg00064.html but that's really just a syntactic short-cut to the run-time use of substitute() and eval(), which you could manually put into a function yourself if you cared too. (AKA, not at all equivalent to Lisp macros.) The mlocal() function in mvbutils also has seemingly similar macro-using-eval properties: http://cran.r-project.org/src/contrib/Descriptions/mvbutils.html http://www.maths.lth.se/help/R/.R/library/mvbutils/html/mlocal.html I could of course pre-process R source code, either using a custom script or something like M5: http://www.soe.ucsc.edu/~brucem/samples.html http://groups.google.com/group/comp.compilers/browse_thread/thread/8ece2f34620f7957/000475ab31140327 But that's not what I'm asking about here. As I understand it, Lisp-style macros manipulate the already-parsed syntax tree. This seems very uncommon in non-Lisp languages and environments, but some - like Python - do have such support. (I don't use Python, but I'm told that its standard parser APIs are as powerful as Lisp macros, although clunkier to use.) Is implementing Lisp-style macros feasible in R? Has anyone investigated this or tried to do it? What internal representation does R use for its parse tree, and how could I go about manipulating it in some fashion, either at package build time or at run time, in order to support true Lisp-style macros? Whenever I try something like this in R: > dput(parse(text="1+2")) expression(1 + 2) what I see looks exactly like R code - that '1 + 2' expression doesn't look very "parsed" to me. Is that really it, or is there some sort of Scheme-like parse tree hiding underneath? I see that the interactive Read-Eval-Print loop basically calls R_Parse1() in "src/main/gram.c", but from there I'm pretty much lost. Also, what happens at package build time? I know that R CMD INSTALL generates binary *.rdb and *.rdx files for my package, but what do those do exactly, and how do they relate to the REPL and R_Parse1()? Finally, are there any docs describing the design and implementation of the R internals? Should I be looking anywhere other than the R developer page here?: http://developer.r-project.org/ Thanks! -- Andrew Piskorski <[EMAIL PROTECTED]> http://www.piskorski.com/ __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Question about colnames behavior
> "Erich" == Erich Neuwirth <[EMAIL PROTECTED]> > on Sun, 02 Oct 2005 09:39:36 +0200 writes: Erich> The following code Erich> zzz<-1:10 Erich> dim(zzz)<-10 Erich> rownames(zzz) Erich> colnames(zzz) Erich> yields NULL for the rownames and colnames calls. Erich> Let us set rownames Erich> rownames(zzz)<-1:10 Erich> Now rownames(zzz) returns the expected result, but colnames(zzz) Erich> produces an error: Erich> Error in dn[[2]] : subscript out of bounds Erich> So given a onedimensional structure the return behavior of colnames Erich> is different depending on the fact if rownames are set or not. Erich> Should the behavior of colnames be changed to make the result Erich> independent from this fact? yes, thank you, Erich. It should give an error also in the 1st case which is BTW identical to zzz <- array(1:10) Not for R 2.2.0 though, but rather 2.2.1. Martin __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Question about colnames behavior
On Mon, 3 Oct 2005, Martin Maechler wrote: >> "Erich" == Erich Neuwirth <[EMAIL PROTECTED]> >> on Sun, 02 Oct 2005 09:39:36 +0200 writes: > >Erich> The following code >Erich> zzz<-1:10 >Erich> dim(zzz)<-10 >Erich> rownames(zzz) >Erich> colnames(zzz) > >Erich> yields NULL for the rownames and colnames calls. >Erich> Let us set rownames > >Erich> rownames(zzz)<-1:10 > >Erich> Now rownames(zzz) returns the expected result, but colnames(zzz) >Erich> produces an error: >Erich> Error in dn[[2]] : subscript out of bounds > >Erich> So given a onedimensional structure the return behavior of colnames >Erich> is different depending on the fact if rownames are set or not. > >Erich> Should the behavior of colnames be changed to make the result >Erich> independent from this fact? > > yes, thank you, Erich. > It should give an error also in the 1st case which is > BTW identical to >zzz <- array(1:10) Not according to my reading of the help, which says The extractor functions try to do something sensible for any matrix-like object 'x'. If the object has 'dimnames' the first component is used as the row names, and the second component (if any) is used for the col names. and reading on, I think it should give NULL in both cases. You could argue that a 1D array is not `matrix-like', but that seems a narrow interpretation (especially as rownames does work for such arrays). > Not for R 2.2.0 though, but rather 2.2.1. Agreed. -- Brian D. Ripley, [EMAIL PROTECTED] 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
[Rd] Foreign function calls without 'PACKAGE' argument (PR#8171)
as title,when I check my own R package It appear the warning:Foreign function calls without 'PACKAGE' argument, I = don't know what's wrongcan somebody help me ,thanks [[alternative HTML version deleted]] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Foreign function calls without 'PACKAGE' argument (PR#8171)
Please do not abuse the R-bugs repository to ask questions. This is made very clear in the FAQ. The meaning of these messages is discussed in the `Writing R Extensions' manual: search for `PACKAGE'. On Mon, 3 Oct 2005 [EMAIL PROTECTED] wrote: > as title,when I check my own R package > It appear the warning:Foreign function calls without 'PACKAGE' argument, I = > don't know what's wrongcan somebody help me ,thanks > [[alternative HTML version deleted]] Please do not send HTML mail, as the posting guide asks. -- Brian D. Ripley, [EMAIL PROTECTED] 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
[Rd] tcltk (PR#8173)
Full_Name: Castagner Michel Version: 2.1.1 OS: Solaris Submission from: (NULL) (195.220.60.11) > library(tcltk) Error in namespaceExport(ns, exports) : undefined exports :addTclPath, as.tclObj, is.tclObj, is.tkwin In addition: Warning message: S3 methods '$.tclvar', '$<-.tclvar', 'as.character.tclObj', 'as.character.tclVar', 'as.double.tclObj', 'as.integer.tclObj', 'as.logical.tclObj', 'print.tclObj', '[[.tclArray', '[[<-.tclArray', '$.tclArray', '$<-.tclArray', 'names.tclArray', 'names<-.tclArray', 'length.tclArray', 'length<-.tclArray', 'tclObj.tclVar', 'tclObj<-.tclVar', 'tclvalue.default', 'tclvalue.tclObj', 'tclvalue.tclVar', 'tclvalue<-.default', 'tclvalue<-.tclVar' were declared in NAMESPACE but not found Error: package/namespace load failed for 'tcltk' __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Question about colnames behavior
> "BDR" == Prof Brian Ripley <[EMAIL PROTECTED]> > on Mon, 3 Oct 2005 09:44:47 +0100 (BST) writes: BDR> On Mon, 3 Oct 2005, Martin Maechler wrote: >>> "Erich" == Erich Neuwirth <[EMAIL PROTECTED]> >>> on Sun, 02 Oct 2005 09:39:36 +0200 writes: >> Erich> The following code Erich> zzz<-1:10 Erich> dim(zzz)<-10 Erich> rownames(zzz) Erich> colnames(zzz) >> Erich> yields NULL for the rownames and colnames calls. Erich> Let us set rownames >> Erich> rownames(zzz)<-1:10 >> Erich> Now rownames(zzz) returns the expected result, but colnames(zzz) Erich> produces an error: Erich> Error in dn[[2]] : subscript out of bounds >> Erich> So given a onedimensional structure the return behavior of colnames Erich> is different depending on the fact if rownames are set or not. >> Erich> Should the behavior of colnames be changed to make the result Erich> independent from this fact? >> >> yes, thank you, Erich. >> It should give an error also in the 1st case which is >> BTW identical to >> zzz <- array(1:10) BDR> Not according to my reading of the help, which says >> The extractor functions try to do something sensible for any >> matrix-like object 'x'. If the object has 'dimnames' the first >> component is used as the row names, and the second component (if >> any) is used for the col names. BDR> and reading on, I think it should give NULL in both cases. You could BDR> argue that a 1D array is not `matrix-like', but that seems a narrow BDR> interpretation (especially as rownames does work for such arrays). I was lead to my conclusion by the same help page, reading >> Arguments: >> >>x: a matrix-like R object, with at least two dimensions for 'colnames'. from which I concluded an error was appropriate for 'colnames' when 'x' doesn't have two dimensions. If we adopt your proposal (NULL in any case), we should definitely also fix that paragraph... Martin __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] access to R parse tree for Lisp-style macros?
On 10/3/2005 3:25 AM, Andrew Piskorski wrote: > R folks, I'm curious about possible support for Lisp-style macros in > R. I'm aware of the "defmacro" support for S-Plus and R discussed > here: > > http://www.biostat.wustl.edu/archives/html/s-news/2002-10/msg00064.html > > but that's really just a syntactic short-cut to the run-time use of > substitute() and eval(), which you could manually put into a function > yourself if you cared too. (AKA, not at all equivalent to Lisp > macros.) The mlocal() function in mvbutils also has seemingly similar > macro-using-eval properties: > > http://cran.r-project.org/src/contrib/Descriptions/mvbutils.html > http://www.maths.lth.se/help/R/.R/library/mvbutils/html/mlocal.html > > I could of course pre-process R source code, either using a custom > script or something like M5: > > http://www.soe.ucsc.edu/~brucem/samples.html > > http://groups.google.com/group/comp.compilers/browse_thread/thread/8ece2f34620f7957/000475ab31140327 > > But that's not what I'm asking about here. As I understand it, > Lisp-style macros manipulate the already-parsed syntax tree. This > seems very uncommon in non-Lisp languages and environments, but some - > like Python - do have such support. (I don't use Python, but I'm told > that its standard parser APIs are as powerful as Lisp macros, although > clunkier to use.) > > Is implementing Lisp-style macros feasible in R? Has anyone > investigated this or tried to do it? > > What internal representation does R use for its parse tree, and how > could I go about manipulating it in some fashion, either at package > build time or at run time, in order to support true Lisp-style macros? It is like a list of lists, with modes attached that say how they are to be interpreted. parse() gives a list of mode "expression", containing a list of function calls or atomic objects. Function calls are stored as a list whose head is the function name with subsequent entries being the arguments. The mode may be "expression", or "call", or others, depending on what you are actually dealing with. > > Whenever I try something like this in R: > > > dput(parse(text="1+2")) > expression(1 + 2) > > what I see looks exactly like R code - that '1 + 2' expression doesn't > look very "parsed" to me. Is that really it, or is there some sort of > Scheme-like parse tree hiding underneath? I see that the interactive > Read-Eval-Print loop basically calls R_Parse1() in "src/main/gram.c", > but from there I'm pretty much lost. There's a parse tree underneath. R is being helpful and deparsing it for you for display purposes. To see it as a list, use "as.list" to strip off the mode, e.g. > as.list(parse(text="1+2")) [[1]] 1 + 2 # A list containing one expression. Expand it: > as.list(parse(text="1+2")[[1]]) [[1]] `+` [[2]] [1] 1 [[3]] [1] 2 # A function call to `+` with two arguments. The arguments are atomic. Use "mode" to work out how these are interpreted: > mode(parse(text="1+2")) [1] "expression" > mode(parse(text="1+2")[[1]]) [1] "call" > > Also, what happens at package build time? I know that R CMD INSTALL > generates binary *.rdb and *.rdx files for my package, but what do > those do exactly, and how do they relate to the REPL and R_Parse1()? > > Finally, are there any docs describing the design and implementation > of the R internals? Should I be looking anywhere other than the R > developer page here?: The source code is sometimes the best place for low level details like this. The R Language manual sometimes gives low level details, but is is uneven in its coverage; I forget if it covers this. Duncan Murdoch __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] access to R parse tree for Lisp-style macros?
On Mon, 3 Oct 2005, Duncan Murdoch wrote: > On 10/3/2005 3:25 AM, Andrew Piskorski wrote: >> R folks, I'm curious about possible support for Lisp-style macros in >> R. I'm aware of the "defmacro" support for S-Plus and R discussed >> here: >> >> http://www.biostat.wustl.edu/archives/html/s-news/2002-10/msg00064.html >> >> but that's really just a syntactic short-cut to the run-time use of >> substitute() and eval(), which you could manually put into a function >> yourself if you cared too. (AKA, not at all equivalent to Lisp >> macros.) Well, yes and no. It is a syntactic shortcut using functions, but what it does is manipulate and then evaluate pieces of parse tree. It doesn't have the efficiency under compilation that real macros would, but we don't have compilation. It doesn't have gensyms, but again, R fails to support these in a fairly fundamental way, so they have to be faked using variables with weird random names. I have a long-term plan to add real macros, but not until after Luke Tierney's byte-code compiler is finished. -thomas __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] storage.mode, C data types and speed
Hi, I am trying to speed up part of an algorithm in which certain columns of a large matrix (X) are replaced by the element-wise product of a matrix (M) and a vector (v). In R, the code might be X[, ind] <- M * v I have written a small C routine to do this for me, but the timing depends on how I define the storage.mode of the objects in R and the data types in C, in a way which I don't understand. To illustrate, suppose I have the following for X, M and v: nr <- 1 X <- matrix(1, nr, 500) M <- matrix(1:(nr*450), nr, 450) v <- 1:nr storage.mode(X) <- storage.mode(M) <- storage.mode(v) <- "double" Then I have the following integers required by my C code - these are the objects which I'm not sure how to handle a <- 50*nr#index of X indicating where to start replacing values nm <- length(M) nv <- length(v) I would have thought I wanted storage.mode(a) <- storage.mode(nm) <- storage.mode(nv) <- "integer" to go with the following C code # include SEXP prod_integer(SEXP X, SEXP M, SEXP v, SEXP a, SEXP nm, SEXP nv) { int i = INTEGER(a)[0], i1 = 0, i2 = 0; for ( ; i1 < INTEGER(nm)[0]; i2 = (++i2 == INTEGER(nv)[0]) ? 0 : i2) { REAL(X)[i++] = REAL(M)[i1++] * REAL(v)[i2]; } return(X); } Running this is R gives the following timings on my PC > dyn.load("D:/C_routines/prod_integer") > for(i in 1:3) {print(system.time(.Call("prod_integer", X, M, v, a, nm, nv)))} [1] 0.17 0.00 0.18 NA NA [1] 0.18 0.00 0.17 NA NA [1] 0.15 0.00 0.17 NA NA But strangely (to me) if I change the storage mode of my integers to "double", I get > storage.mode(a) <- storage.mode(nm) <- storage.mode(nv) <- "double" > for(i in 1:3) {print(system.time(.Call("prod_integer", X, M, v, a, nm, nv)))} [1] 0 0 0 NA NA [1] 0 0 0 NA NA [1] 0 0 0 NA NA If on the other hand I use REAL instead of INTEGER in my C code: # include SEXP prod_real(SEXP X, SEXP M, SEXP v, SEXP a, SEXP nm, SEXP nv) { int i = REAL(a)[0], i1 = 0, i2 = 0; for ( ; i1 < REAL(nm)[0]; i2 = (++i2 == REAL(nv)[0]) ? 0 : i2) { REAL(X)[i++] = REAL(M)[i1++] * REAL(v)[i2]; } return(X); } The reverse is true: > storage.mode(a) <- storage.mode(nm) <- storage.mode(nv) <- "integer" > for(i in 1:3) {print(system.time(.Call("prod_real", X, M, v, a, nm, nv)))} [1] 0 0 0 NA NA [1] 0 0 0 NA NA [1] 0 0 0 NA NA > storage.mode(a) <- storage.mode(nm) <- storage.mode(nv) <- "double" > for(i in 1:3) {print(system.time(.Call("prod_real", X, M, v, a, nm, nv)))} [1] 0.22 0.00 0.22 NA NA [1] 0.21 0.00 0.20 NA NA [1] 0.21 0.00 0.22 NA NA > identical(.Call("prod_integer", X, M, v, a, nm, nv), .Call("prod_real", X, M, > v, a, nm, nv)) [1] TRUE So I seem to get the fastest results if I store a, nm and nv as doubles in R and treat them as integers in C or if I store them as integers in R and treat them as doubles in C, rather than matching the storage in R to the data type in C. I must be misunderstanding something here. Can someone explain what's going on - please note I have only just begun to learn C, apologies if this is a basic C issue. Thanks, Heather Dr H Turner Research Assistant Dept. of Statistics The University of Warwick Coventry CV4 7AL Tel: 024 76575870 Url: www.warwick.ac.uk/go/heatherturner __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Problem Sweaving vignettes: MiKTeX's texi2dvi reports errors
Hi, Prof. Ripley, Yes, indeed, that was my problem - thank you! I made the mistake of installing in the default path of C:\Program Files\R. I just now reinstalled in C:\R, and everything worked fine. However, if anyone else runs into this, you cannot just go off and run texi2dvi on an existing .tex file after installing in a non-space path: you should rerun the whole Sweave example, which forces a number of additional required items to be downloaded. Let that process complete, then rerun again. It works fine! The finished pdf file sure looks sweet. Thank you again! Regards, = Peter -Original Message- From: Prof Brian Ripley [mailto:[EMAIL PROTECTED] Sent: Sunday, October 02, 2005 3:01 PM To: Peter G. Warren Cc: r-devel@r-project.org Subject: Re: [Rd] Problem Sweaving vignettes: MiKTeX's texi2dvi reports errors I get > texi2dvi("Sweave-test-1.tex", pdf=TRUE, quiet=FALSE) This is pdfeTeX, Version 3.141592-1.20a-rc7.2-2.2 (MiKTeX 2.4) output format initialized to PDF entering extended mode (Sweave-test-1.tex LaTeX2e <2003/12/01> Babel and hyphenation patterns for english, french, german, ngerman, dumylang, nohyphenation, loaded. (C:\packages\MikTeX\tex\latex\base\article.cls Document Class: article 2004/02/16 v1.4f Standard LaTeX document class (C:\packages\MikTeX\tex\latex\base\size10.clo)) (C:\packages\MikTeX\tex\latex\ltxmisc\a4wide.sty (C:\packages\MikTeX\tex\latex\ntgclass\a4.sty)) (d:/R/svn/trunk/share/texmf/Sweave.sty LaTeX Warning: You have requested package `d:/R/svn/trunk/share/texmf/Sweave', but the package provides `Sweave'. so my guess is that this a path problem with your MiKTeX and it is not finding Sweave.sty. Simple questions: where did you install R? Is there a space in the path? On Sun, 2 Oct 2005, Peter G. Warren wrote: > Hi, > > I am trying to create a Bioconductor package. Everything installs and > checks fine. Now I'm on my last step, which is to create a vignette. > I'm trying to test the Sweave process, to make sure I can build a > vignette. I am stuck at the texi2dvi stage, which fails when I try to > process the example Sweave-test-1.tex file. > > I am using Windows binary R distributions, and have the same problem > on both the latest developer version (2.2.0 Beta) and the latest > patched version > (2.1.1) . For the Tex processing, I first tried downloading and > installing fpTex, but found that it doesn't have texi2dvi. Some > Googling informed me that recent MiKTeX versions now have that > function, so I just downloaded that (the small installation). Indeed > there is a texi2dvi. The first time I ran it, it downloaded a class file it needed, so now it at least executes. > However, when I try to run it on the test Sweave tex file, I get an error. > Here's the sequence in R: > >> library(tools) >> example(Sweave) > [...output suppressed] >> texi2dvi("Sweave-test-1.tex", pdf=TRUE, quiet=FALSE) > Error in texi2dvi("Sweave-test-1.tex", pdf=TRUE, quiet = FALSE) : >running texi2dvi on 'Sweave-test-1.tex' failed > > [A command window pops up, and the following is from that window: ] > > This is pdfeTeX, Version 3.141592-1.20a-rc7.2-2.2 (MiKTeX 2.4) output > format initialized to PDF entering extended mode (Sweave-test-1.tex > LaTeX2e <2003/12/01> Babel and hyphenation patterns for > english, french, german, ngerman, du mylang, nohyphenation, loaded. > (C:\MiKTex\texmf\tex\latex\base\article.cls > Document Class: article 2004/02/16 v1.4f Standard LaTeX document class > (C:\MiKTex\texmf\tex\latex\base\size10.clo)) > (C:\MiKTex\texmf\tex\latex\ltxmisc\a4wide.sty > (C:\MiKTex\texmf\tex\latex\ntgclass\a4.sty)) > ! Missing \endcsname inserted. > > \protect > l.11 \begin > {document} > ? > > [ Here, I hit a , and get the following:] > > ! LaTeX Error: Missing \begin{document}. > > See the LaTeX manual or LaTeX Companion for explanation. > Type H for immedi ate help. > ... > > l.11 \begin > {document} > ? > > - > I have also tried running texi2dvi directly on the command line, and > get the same result. I've looked at the manual on the MiKTeX site, but > find nothing that tells me what may be wrong. The Sweave test file > looks fine to me. I have also tried running texify --pdf on the same > file on the command line, but get the same results exactly. > > I also went to the R-tools site, and went through their page on MiKTeX > issues. Using their second suggestion (since I'm using the recent > MiKTeX version, which defaults to e-TeX mode), I tried changing the > mode for texinfo from e-TeX Extended to e-TeX Compatibility mode: no > change in results. (I'm assuming that texi2dvi is part of texinfo > package - please correct me if I'm wrong.) [I also tried changing > texinfo from e-TeX to TeX mode, and rebuilt/reloade/refreshed, but > this did not seem to take: texi2dvi still reports that it's in e-TeX > mode.] > > Finally, I did try posting this to the bioc-devel list
Re: [Rd] storage.mode, C data types and speed
If nm is double, very likely INTEGER(nm)[0] is negative and your C code does nothing at all. Hence it could be fast but useless. On Mon, 3 Oct 2005, Heather Turner wrote: > Hi, > > I am trying to speed up part of an algorithm in which certain columns of > a large matrix (X) are replaced by the element-wise product of a matrix > (M) and a vector (v). In R, the code might be > > X[, ind] <- M * v > > I have written a small C routine to do this for me, but the timing > depends on how I define the storage.mode of the objects in R and the > data types in C, in a way which I don't understand. > > To illustrate, suppose I have the following for X, M and v: > nr <- 1 > X <- matrix(1, nr, 500) > M <- matrix(1:(nr*450), nr, 450) > v <- 1:nr > storage.mode(X) <- storage.mode(M) <- storage.mode(v) <- "double" > > Then I have the following integers required by my C code - these are the > objects which I'm not sure how to handle > a <- 50*nr#index of X indicating where to start replacing values > nm <- length(M) > nv <- length(v) > > I would have thought I wanted > > storage.mode(a) <- storage.mode(nm) <- storage.mode(nv) <- "integer" > > to go with the following C code > > # include > > SEXP prod_integer(SEXP X, SEXP M, SEXP v, SEXP a, SEXP nm, SEXP nv) { > int i = INTEGER(a)[0], i1 = 0, i2 = 0; > > for ( ; i1 < INTEGER(nm)[0]; i2 = (++i2 == INTEGER(nv)[0]) ? 0 : i2) { >REAL(X)[i++] = REAL(M)[i1++] * REAL(v)[i2]; > } > return(X); > } > > Running this is R gives the following timings on my PC > >> dyn.load("D:/C_routines/prod_integer") >> for(i in 1:3) {print(system.time(.Call("prod_integer", X, M, v, a, nm, nv)))} > [1] 0.17 0.00 0.18 NA NA > [1] 0.18 0.00 0.17 NA NA > [1] 0.15 0.00 0.17 NA NA > > But strangely (to me) if I change the storage mode of my integers to > "double", I get > >> storage.mode(a) <- storage.mode(nm) <- storage.mode(nv) <- "double" >> for(i in 1:3) {print(system.time(.Call("prod_integer", X, M, v, a, nm, nv)))} > [1] 0 0 0 NA NA > [1] 0 0 0 NA NA > [1] 0 0 0 NA NA > > If on the other hand I use REAL instead of INTEGER in my C code: > > # include > > SEXP prod_real(SEXP X, SEXP M, SEXP v, SEXP a, SEXP nm, SEXP nv) { > int i = REAL(a)[0], i1 = 0, i2 = 0; > > for ( ; i1 < REAL(nm)[0]; i2 = (++i2 == REAL(nv)[0]) ? 0 : i2) { >REAL(X)[i++] = REAL(M)[i1++] * REAL(v)[i2]; > } > return(X); > } > > The reverse is true: >> storage.mode(a) <- storage.mode(nm) <- storage.mode(nv) <- "integer" >> for(i in 1:3) {print(system.time(.Call("prod_real", X, M, v, a, nm, nv)))} > [1] 0 0 0 NA NA > [1] 0 0 0 NA NA > [1] 0 0 0 NA NA >> storage.mode(a) <- storage.mode(nm) <- storage.mode(nv) <- "double" >> for(i in 1:3) {print(system.time(.Call("prod_real", X, M, v, a, nm, nv)))} > [1] 0.22 0.00 0.22 NA NA > [1] 0.21 0.00 0.20 NA NA > [1] 0.21 0.00 0.22 NA NA >> identical(.Call("prod_integer", X, M, v, a, nm, nv), .Call("prod_real", X, >> M, v, a, nm, nv)) > [1] TRUE > > So I seem to get the fastest results if I store a, nm and nv as doubles in R > and treat them as integers in C or if I store them as integers in R and treat > them as doubles in C, rather than matching the storage in R to the data type > in C. > > I must be misunderstanding something here. Can someone explain what's going > on - please note I have only just begun to learn C, apologies if this is a > basic C issue. > > Thanks, > > Heather > > Dr H Turner > Research Assistant > Dept. of Statistics > The University of Warwick > Coventry > CV4 7AL > > Tel: 024 76575870 > Url: www.warwick.ac.uk/go/heatherturner > > __ > R-devel@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel > > -- Brian D. Ripley, [EMAIL PROTECTED] 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
Re: [Rd] Problem Sweaving vignettes: MiKTeX's texi2dvi reports errors
On Mon, 3 Oct 2005, Peter G. Warren wrote: > Hi, Prof. Ripley, > > Yes, indeed, that was my problem - thank you! I made the mistake of > installing in the default path of C:\Program Files\R. I just now reinstalled > in C:\R, and everything worked fine. However, if anyone else runs into this, > you cannot just go off and run texi2dvi on an existing .tex file after > installing in a non-space path: you should rerun the whole Sweave example, > which forces a number of additional required items to be downloaded. Indeed as the path is hardcoded in the .tex file generated by Sweave. In my case % -*- mode: noweb; noweb-default-code-mode: R-mode; -*- \documentclass[a4paper]{article} \title{A Test File} \author{Friedrich Leisch} \usepackage{a4wide} \usepackage{d:/R/svn/trunk/share/texmf/Sweave} > Let that process complete, then rerun again. It works fine! The finished > pdf file sure looks sweet. Good. We should try to fix this at R level if we can. To Fritz Leisch: I presume this is coming from RweaveLatexSetup's if(stylepath){ styfile <- file.path(R.home("share"), "texmf", "Sweave") if(.Platform$OS.type == "windows") styfile <- gsub("", "/", styfile) if(any(grep(" ", styfile))) warning(gettextf("path to '%s' contains spaces,\n", styfile), gettext("this may cause problems when running LaTeX"), domain = NA) } else styfile <- "Sweave" So, there should have been a warning that seems not to have been seen. However, if we added the opposite of normalizePath() to form the short path, would that fix this? > > Thank you again! > > Regards, > = Peter > > -Original Message- > From: Prof Brian Ripley [mailto:[EMAIL PROTECTED] > Sent: Sunday, October 02, 2005 3:01 PM > To: Peter G. Warren > Cc: r-devel@r-project.org > Subject: Re: [Rd] Problem Sweaving vignettes: MiKTeX's texi2dvi reports > errors > > I get > >> texi2dvi("Sweave-test-1.tex", pdf=TRUE, quiet=FALSE) > This is pdfeTeX, Version 3.141592-1.20a-rc7.2-2.2 (MiKTeX 2.4) output format > initialized to PDF entering extended mode (Sweave-test-1.tex LaTeX2e > <2003/12/01> Babel and hyphenation patterns for english, french, > german, ngerman, dumylang, nohyphenation, loaded. > (C:\packages\MikTeX\tex\latex\base\article.cls > Document Class: article 2004/02/16 v1.4f Standard LaTeX document class > (C:\packages\MikTeX\tex\latex\base\size10.clo)) > (C:\packages\MikTeX\tex\latex\ltxmisc\a4wide.sty > (C:\packages\MikTeX\tex\latex\ntgclass\a4.sty)) > (d:/R/svn/trunk/share/texmf/Sweave.sty > > LaTeX Warning: You have requested package > `d:/R/svn/trunk/share/texmf/Sweave', >but the package provides `Sweave'. > > so my guess is that this a path problem with your MiKTeX and it is not > finding Sweave.sty. > > Simple questions: where did you install R? Is there a space in the path? > > > On Sun, 2 Oct 2005, Peter G. Warren wrote: > >> Hi, >> >> I am trying to create a Bioconductor package. Everything installs and >> checks fine. Now I'm on my last step, which is to create a vignette. >> I'm trying to test the Sweave process, to make sure I can build a >> vignette. I am stuck at the texi2dvi stage, which fails when I try to >> process the example Sweave-test-1.tex file. >> >> I am using Windows binary R distributions, and have the same problem >> on both the latest developer version (2.2.0 Beta) and the latest >> patched version >> (2.1.1) . For the Tex processing, I first tried downloading and >> installing fpTex, but found that it doesn't have texi2dvi. Some >> Googling informed me that recent MiKTeX versions now have that >> function, so I just downloaded that (the small installation). Indeed >> there is a texi2dvi. The first time I ran it, it downloaded a class file > it needed, so now it at least executes. >> However, when I try to run it on the test Sweave tex file, I get an error. >> Here's the sequence in R: >> >>> library(tools) >>> example(Sweave) >> [...output suppressed] >>> texi2dvi("Sweave-test-1.tex", pdf=TRUE, quiet=FALSE) >> Error in texi2dvi("Sweave-test-1.tex", pdf=TRUE, quiet = FALSE) : >>running texi2dvi on 'Sweave-test-1.tex' failed >> >> [A command window pops up, and the following is from that window: ] >> >> This is pdfeTeX, Version 3.141592-1.20a-rc7.2-2.2 (MiKTeX 2.4) output >> format initialized to PDF entering extended mode (Sweave-test-1.tex >> LaTeX2e <2003/12/01> Babel and hyphenation patterns for >> english, french, german, ngerman, du mylang, nohyphenation, loaded. >> (C:\MiKTex\texmf\tex\latex\base\article.cls >> Document Class: article 2004/02/16 v1.4f Standard LaTeX document class >> (C:\MiKTex\texmf\tex\latex\base\size10.clo)) >> (C:\MiKTex\texmf\tex\latex\ltxmisc\a4wide.sty >> (C:\MiKTex\texmf\tex\latex\ntgclass\a4.sty)) >> ! Missing \endcsname inserted. >> >> \protect >> l.11 \begin >> {document} >> ? >> >> [ Here, I hit a , and get the fol
Re: [Rd] Problem Sweaving vignettes: MiKTeX's texi2dvi reports errors
I have R installed in c:\Program Files\R and I use MiKTeX and texi2dvi to process my vignettes. I do keep my package sources elsewhere; e.g. I would keep the source for mypkg in c:\Rpkgs\mypkg . and I would install it into c:\Rpkg\library or once I am ready to use it in production into e.g. c:\Program Files\R\rw2011pat\library thus I don't think its necessary to relocate R itself. On 10/3/05, Peter G. Warren <[EMAIL PROTECTED]> wrote: > Hi, Prof. Ripley, > > Yes, indeed, that was my problem - thank you! I made the mistake of > installing in the default path of C:\Program Files\R. I just now reinstalled > in C:\R, and everything worked fine. However, if anyone else runs into this, > you cannot just go off and run texi2dvi on an existing .tex file after > installing in a non-space path: you should rerun the whole Sweave example, > which forces a number of additional required items to be downloaded. Let > that process complete, then rerun again. It works fine! The finished pdf > file sure looks sweet. > > Thank you again! > > Regards, > = Peter > > -Original Message- > From: Prof Brian Ripley [mailto:[EMAIL PROTECTED] > Sent: Sunday, October 02, 2005 3:01 PM > To: Peter G. Warren > Cc: r-devel@r-project.org > Subject: Re: [Rd] Problem Sweaving vignettes: MiKTeX's texi2dvi reports > errors > > I get > > > texi2dvi("Sweave-test-1.tex", pdf=TRUE, quiet=FALSE) > This is pdfeTeX, Version 3.141592-1.20a-rc7.2-2.2 (MiKTeX 2.4) output format > initialized to PDF entering extended mode (Sweave-test-1.tex LaTeX2e > <2003/12/01> Babel and hyphenation patterns for english, french, > german, ngerman, dumylang, nohyphenation, loaded. > (C:\packages\MikTeX\tex\latex\base\article.cls > Document Class: article 2004/02/16 v1.4f Standard LaTeX document class > (C:\packages\MikTeX\tex\latex\base\size10.clo)) > (C:\packages\MikTeX\tex\latex\ltxmisc\a4wide.sty > (C:\packages\MikTeX\tex\latex\ntgclass\a4.sty)) > (d:/R/svn/trunk/share/texmf/Sweave.sty > > LaTeX Warning: You have requested package > `d:/R/svn/trunk/share/texmf/Sweave', >but the package provides `Sweave'. > > so my guess is that this a path problem with your MiKTeX and it is not > finding Sweave.sty. > > Simple questions: where did you install R? Is there a space in the path? > > > On Sun, 2 Oct 2005, Peter G. Warren wrote: > > > Hi, > > > > I am trying to create a Bioconductor package. Everything installs and > > checks fine. Now I'm on my last step, which is to create a vignette. > > I'm trying to test the Sweave process, to make sure I can build a > > vignette. I am stuck at the texi2dvi stage, which fails when I try to > > process the example Sweave-test-1.tex file. > > > > I am using Windows binary R distributions, and have the same problem > > on both the latest developer version (2.2.0 Beta) and the latest > > patched version > > (2.1.1) . For the Tex processing, I first tried downloading and > > installing fpTex, but found that it doesn't have texi2dvi. Some > > Googling informed me that recent MiKTeX versions now have that > > function, so I just downloaded that (the small installation). Indeed > > there is a texi2dvi. The first time I ran it, it downloaded a class file > it needed, so now it at least executes. > > However, when I try to run it on the test Sweave tex file, I get an error. > > Here's the sequence in R: > > > >> library(tools) > >> example(Sweave) > > [...output suppressed] > >> texi2dvi("Sweave-test-1.tex", pdf=TRUE, quiet=FALSE) > > Error in texi2dvi("Sweave-test-1.tex", pdf=TRUE, quiet = FALSE) : > >running texi2dvi on 'Sweave-test-1.tex' failed > > > > [A command window pops up, and the following is from that window: ] > > > > This is pdfeTeX, Version 3.141592-1.20a-rc7.2-2.2 (MiKTeX 2.4) output > > format initialized to PDF entering extended mode (Sweave-test-1.tex > > LaTeX2e <2003/12/01> Babel and hyphenation patterns for > > english, french, german, ngerman, du mylang, nohyphenation, loaded. > > (C:\MiKTex\texmf\tex\latex\base\article.cls > > Document Class: article 2004/02/16 v1.4f Standard LaTeX document class > > (C:\MiKTex\texmf\tex\latex\base\size10.clo)) > > (C:\MiKTex\texmf\tex\latex\ltxmisc\a4wide.sty > > (C:\MiKTex\texmf\tex\latex\ntgclass\a4.sty)) > > ! Missing \endcsname inserted. > > > > \protect > > l.11 \begin > > {document} > > ? > > > > [ Here, I hit a , and get the following:] > > > > ! LaTeX Error: Missing \begin{document}. > > > > See the LaTeX manual or LaTeX Companion for explanation. > > Type H for immedi ate help. > > ... > > > > l.11 \begin > > {document} > > ? > > > > - > > I have also tried running texi2dvi directly on the command line, and > > get the same result. I've looked at the manual on the MiKTeX site, but > > find nothing that tells me what may be wrong. The Sweave test file > > looks fine to me. I have also tried running texify --pdf on the same > > file on the command line, but get the same results exactly.
Re: [Rd] Problem Sweaving vignettes: MiKTeX's texi2dvi reports errors
> On Mon, 3 Oct 2005 11:31:40 -0400, > Gabor Grothendieck (GG) wrote: > I have R installed in c:\Program Files\R and I use MiKTeX and texi2dvi > to process my vignettes. I do keep my package sources elsewhere; > e.g. I would keep the source for mypkg in c:\Rpkgs\mypkg . > and I would install it into c:\Rpkg\library or once I am ready to use it > in production into e.g. c:\Program Files\R\rw2011pat\library > thus I don't think its necessary to relocate R itself. The problem is the path to the *style file* sitting in $RHOME/share/texmf, so having the packages in a different place has nothing to do with it. It is also not really necessary to relocate R itself, you just have to move the style file to some place where latex finds it (e.g., by including $RHOME/share/texmf in your TEXINPUTS path ... but that will make troubles when the path contains spaces and we are back at the beginning). .f __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Problem Sweaving vignettes: MiKTeX's texi2dvi reports errors
> On Mon, 3 Oct 2005 16:30:24 +0100 (BST), > Prof Brian Ripley (PBR) wrote: > On Mon, 3 Oct 2005, Peter G. Warren wrote: >> Hi, Prof. Ripley, >> >> Yes, indeed, that was my problem - thank you! I made the mistake of >> installing in the default path of C:\Program Files\R. I just now reinstalled >> in C:\R, and everything worked fine. However, if anyone else runs into this, >> you cannot just go off and run texi2dvi on an existing .tex file after >> installing in a non-space path: you should rerun the whole Sweave example, >> which forces a number of additional required items to be downloaded. > Indeed as the path is hardcoded in the .tex file generated by Sweave. In > my case > % -*- mode: noweb; noweb-default-code-mode: R-mode; -*- > \documentclass[a4paper]{article} > \title{A Test File} > \author{Friedrich Leisch} > \usepackage{a4wide} > \usepackage{d:/R/svn/trunk/share/texmf/Sweave} >> Let that process complete, then rerun again. It works fine! The finished >> pdf file sure looks sweet. > Good. We should try to fix this at R level if we can. To Fritz Leisch: I > presume this is coming from RweaveLatexSetup's > if(stylepath){ > styfile <- file.path(R.home("share"), "texmf", "Sweave") > if(.Platform$OS.type == "windows") > styfile <- gsub("", "/", styfile) > if(any(grep(" ", styfile))) > warning(gettextf("path to '%s' contains spaces,\n", styfile), > gettext("this may cause problems when running LaTeX"), > domain = NA) > } > else > styfile <- "Sweave" Yes. > So, there should have been a warning that seems not to have been seen. > However, if we added the opposite of normalizePath() to form the short > path, would that fix this? Actually, thinking about it again makes me wonder if the best solution isn't to simply copy the few lines I need to the .tex file if no \usepackage[...]{Sweave} is found. Too late for 2.2.0 but I would consider the problem a bug, so could try to fix it for 2.2.1. Best, Fritz -- --- Friedrich Leisch Institut für Statistik Tel: (+43 1) 58801 10715 Technische Universität WienFax: (+43 1) 58801 10798 Wiedner Hauptstraße 8-10/1071 A-1040 Wien, Austria http://www.ci.tuwien.ac.at/~leisch __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Problem Sweaving vignettes: MiKTeX's texi2dvi reports errors
There is a batch file in batchfiles at http://cran.r-project.org/contrib/extra/batchfiles/ that copies the .sty files to miktex's directory. This is also discussed on Duncan's rtools MiKTeX site. My understanding is that this will not be necessary from R 2.2.0 onwards but was needed previously. On 10/3/05, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > On Mon, 3 Oct 2005 11:31:40 -0400, > > Gabor Grothendieck (GG) wrote: > > > I have R installed in c:\Program Files\R and I use MiKTeX and texi2dvi > > to process my vignettes. I do keep my package sources elsewhere; > > e.g. I would keep the source for mypkg in c:\Rpkgs\mypkg . > > and I would install it into c:\Rpkg\library or once I am ready to use it > > in production into e.g. c:\Program Files\R\rw2011pat\library > > thus I don't think its necessary to relocate R itself. > > The problem is the path to the *style file* sitting in > $RHOME/share/texmf, so having the packages in a different place has > nothing to do with it. It is also not really necessary to relocate R > itself, you just have to move the style file to some place where latex > finds it (e.g., by including $RHOME/share/texmf in your TEXINPUTS path > ... but that will make troubles when the path contains spaces and we > are back at the beginning). > > .f > __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] interpolation using akima (PR#8174)
Full_Name: Jonathan Lees Version: 2.0.1 OS: linux-gnu Submission from: (NULL) (152.2.75.65) there is a problem with calculating the convex hull in 2-D interpolation using the codes interp fromt eh akima package: x =c(0.6505304, -1.1821562, -0.2600792, 0.7913716) y = c(1.0424226, 0.1754048, -1.4523334, 0.2349112) z = c(0.000, 3.042, 0.370, 0.122) EX = seq(from=min(x), to=max(x), length=100) WHY = seq(from=min(y), to=max(y), length=100) ZZ = interp(x=x, y=y, z=z, xo=EX, yo=WHY, extrap=FALSE) plot(x,y, type='n') image(ZZ, add=TRUE) points(x,y) text(x,y,labels=z) BUG: Notice the convex hull is wrong. It includes only 3 of the 4 points provided. If you add another point near by it does some really wierd stuff. x = c(x, -0.3950865) y = c(y, -1.449117) z = c(z, .37) I do not think it should behave in this manner. __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] interpolation using akima (PR#8174)
Please do read the posting guide and FAQ, as we do ask you to do before sending a bug report. 1) Your version of R is not current. 2) akima is a contributed package and you are not the maintainer. We do ask you not to `behave in this manner'. On Mon, 3 Oct 2005 [EMAIL PROTECTED] wrote: > Full_Name: Jonathan Lees > Version: 2.0.1 > OS: linux-gnu > Submission from: (NULL) (152.2.75.65) > > > there is a problem with calculating the convex hull in 2-D interpolation using > the codes interp fromt eh akima package: > > x =c(0.6505304, -1.1821562, -0.2600792, 0.7913716) > y = c(1.0424226, 0.1754048, -1.4523334, 0.2349112) > z = c(0.000, 3.042, 0.370, 0.122) > > > EX = seq(from=min(x), to=max(x), length=100) >WHY = seq(from=min(y), to=max(y), length=100) > > ZZ = interp(x=x, y=y, z=z, xo=EX, yo=WHY, extrap=FALSE) > > plot(x,y, type='n') > image(ZZ, add=TRUE) > points(x,y) > text(x,y,labels=z) > > BUG: > Notice the convex hull is wrong. > It includes only 3 of the 4 points provided. > If you add another point near by it does some > really wierd stuff. > x = c(x, -0.3950865) > y = c(y, -1.449117) > z = c(z, .37) > > > > I do not think it should behave in this manner. -- Brian D. Ripley, [EMAIL PROTECTED] 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
Re: [Rd] interpolation using akima (PR#8174)
This message should be sent to the package maintainer, not to this list. Moreover, it works fine with my installation (i.e., I don't get the bug you describe): R: platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status beta major2 minor2.0 year 2005 month09 day 24 svn rev 35666 language R akima: Package: akima Version: 0.4-5 Date: 2005-07-21 Best, Renaud 2005/10/3, [EMAIL PROTECTED] <[EMAIL PROTECTED]>: > Full_Name: Jonathan Lees > Version: 2.0.1 > OS: linux-gnu > Submission from: (NULL) (152.2.75.65) > > > there is a problem with calculating the convex hull in 2-D interpolation using > the codes interp fromt eh akima package: > > x =c(0.6505304, -1.1821562, -0.2600792, 0.7913716) > y = c(1.0424226, 0.1754048, -1.4523334, 0.2349112) > z = c(0.000, 3.042, 0.370, 0.122) > > >EX = seq(from=min(x), to=max(x), length=100) > WHY = seq(from=min(y), to=max(y), length=100) > > ZZ = interp(x=x, y=y, z=z, xo=EX, yo=WHY, extrap=FALSE) > > plot(x,y, type='n') > image(ZZ, add=TRUE) > points(x,y) > text(x,y,labels=z) > > BUG: > Notice the convex hull is wrong. > It includes only 3 of the 4 points provided. > If you add another point near by it does some > really wierd stuff. > x = c(x, -0.3950865) > y = c(y, -1.449117) > z = c(z, .37) > > > > I do not think it should behave in this manner. > > __ > R-devel@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel > -- Renaud LANCELOT Directeur Adjoint chargé des Affaires Scientifiques Deputy Director for Scientific Affairs Département EMVT du CIRAD, TA 30/B Campus International de Baillarguet 34398 Montpellier Cedex 5 - France Tel. +33 (0)4 67 59 37 17 Secr. +33 (0)4 67 59 39 04 Fax +33 (0)4 67 59 37 95 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel