Re: [Rd] arguments to .Call(), .External should be read-only?

2014-07-08 Thread Dirk Eddelbuettel
It's one of my favourite Rcpp puzzles: R> cppFunction('bool foo(NumericVector x) { x = 2 * x; return(true); }') R> x <- 1:4 # note that x is now an int vector R> foo(x) # so this casts to numeric --> copy [1] TRUE R> x [1] 1 2 3 4 # s

Re: [Rd] arguments to .Call(), .External should be read-only?

2014-07-08 Thread Duncan Murdoch
On 08/07/2014 10:05 AM, Greg Minshall wrote: hi. if i'm reading correctly, "Writing R Extensions" appears to be inconsistent on the question of whether the arguments passed to a routine called via .Call() or .External() should considered read-only. section 5.2, "Interface functions .C and .Fortr

[Rd] arguments to .Call(), .External should be read-only?

2014-07-08 Thread Greg Minshall
hi. if i'm reading correctly, "Writing R Extensions" appears to be inconsistent on the question of whether the arguments passed to a routine called via .Call() or .External() should considered read-only. section 5.2, "Interface functions .C and .Fortran", says However, when character vectors

[Rd] [OT] Re: a question about optim.R and optim.c in R

2014-07-08 Thread Dirk Eddelbuettel
(flagged thread as OT as this is now orthogonal to the OP's question) On 8 July 2014 at 08:41, Prof J C Nash (U30A) wrote: | Side comment: At UseR last week, Yihui Xie sat with me and we | implemented a Fortran language engine for knitr. It looks like a Pascal | one may also be possible, and mayb

[Rd] a question about optim.R and optim.c in R

2014-07-08 Thread Prof J C Nash (U30A)
As you dig deeper you will find vmmin.c, cgmin.c and (I think) nmmin.c etc. Those were, as I understand, converted by p2c from my Pascal codes that you can find in the pascal library on netlib.org. These can be run with the Free Pascal compiler. Given how long ago these were developed (>30 years i

Re: [Rd] using R functions in a C loop

2014-07-08 Thread Sean O'Riordain
Enrico, I was in a similar position with a small likelihood function which was not vectorizable (is that a word?) and in one morning I had a working function using Rcpp which was 60 times faster than my reference function in R. I *strongly* recommend that you use C++ through the Rcpp interface whic

[Rd] using R functions in a C loop

2014-07-08 Thread Enrico Bibbona
I would like to write a fast version of a function which contains slow loops that I cannot vectorize. I would like to rewrite it in C, but in the loops I need to call a few (two) R functions. Which is the best way to do so? I have read that one can call a C library which import all the R functions