Skip to content

[Rcpp-devel] Rcpp-devel Digest, Vol 12, Issue 8

4 messages · Christian Gunning, Dirk Eddelbuettel, Douglas Bates

#
It might be easier for optim to return an SEXP, i.e. a wrapped Rcpp
object, rather than a pointer/reference to place the object in.  The
resulting SEXP can be returned directly to R (which is what you want,
right?).  Packing a Rcpp::List with value, deriv, etc. inside optim
might make sense here.
Yes, I've used this successfully.  I have run into trouble extracting
elements of length>1 from lists with variable-length elements, e.g.
_mylist = list(a=1, b=1:3), mylist["a"] works but mylist["b"] is
squirrely.
Yes.

hth,
Christian
#
On 8 October 2010 at 04:28, Christian Gunning wrote:
| Yes, I've used this successfully.  I have run into trouble extracting
| elements of length>1 from lists with variable-length elements, e.g.
| _mylist = list(a=1, b=1:3), mylist["a"] works but mylist["b"] is
| squirrely.

Please send a reproducible test case.  I use the same approach a lot and have
not had issues.

Dirk
#
Not sure that I saw the original posting from Vinh but it may be
helpful to know that there is an example that uses Rcpp classes to do
much of packaging of the function, arguments, initial values, etc. in
the minqa package
On Fri, Oct 8, 2010 at 5:28 AM, Christian Gunning <xian at unm.edu> wrote:
#
On Fri, Oct 8, 2010 at 5:33 AM, Dirk Eddelbuettel <edd at debian.org> wrote:
Ah. I see now that, in the example above, mylist["a"] is a 1-length
NumericVector and (mylist["b"])[1] is a double.  My confustion was
using (mylist["b"])[1] in places that expected a NumericVector (like
Rf_PrintValue() or return() ), or trying to pull the single element
into a NumericVector:

NumericVector i(mylist["b]);

which, of course, initializes a NumericVector of length mylist["b"].

Thanks,
Christian