[Rcpp-devel] passing lists to c++
Ott Toomet
OTTT at asb.dk
Fri Nov 13 15:42:53 CET 2009
Dear Dirk,
I currently just sent you the modified API. I havent included any checks or anything and don't want to put too much effort on that until we agree on what to do and what not to do.
Actually, I have problems with accessing anonymous svn (because the firewall blocks most of the stuff). Developer svn works (as ssh port is open). But the tarball at r-forge is pretty up-to-date?
About getting SEXP-s from the list... My arguments:
* It feels more complete to be able to handle all types of R objects (well, excluding more esoteric ones)
* It makes it easier to switch from R to C++ if the task is to boost the speed while maintaining the API. Unwrapping a list is possible but you have to re-design the arguments. This may be complicated if the list is of complex structure.
* What about variable number of list components? My problem is that one of the sublists of my list have varying number of components (being lists of 2 numeric vectors each).
About extracting by position:
* If you have variable number of components, you would rather want to know the total number of them, and thereafter extract them by position than paste string to someting like "comp1", "comp2" etc.
* It feels more R-sh to be able to index both by names and positions.
So, what do you think? My motivation is to use a stable API which fits my needs (not to depend on my own hacks). Perhaps to introduce another extractor instead of RcppParams to deal with lists (RcppListVector)? Or can this be done by the new internal SEXP structure?
Best,
Ott
-----Original Message-----
From: Dirk Eddelbuettel [mailto:edd at debian.org]
Sent: Fri 11/13/2009 2:04 PM
To: Ott Toomet
Cc: rcpp-devel at lists.r-forge.r-project.org
Subject: Re: [Rcpp-devel] (no subject)
Hi Ott,
Replying to both your emails at once/
On 13 November 2009 at 10:38, Ott Toomet wrote:
| Dear Dirk (& possibly others)
|
| I am modifying RcppParams for my needs (you remember our discussion
| yesterday). Seems to be a quite easy task. However, why do you require
| all the parameters to be named? What about allowing non-named parameters
| and implementing access by position? (This is what I do for my purpose,
| but I'd like to rely on something more stable than my own hacks). I would
| be happy to provide some voluntary help here ;-)
Access-by-name is how the rest of the package works. Consistency is good.
Access by position can have its advantages, but it can also be more
error-prone. Changes, if any, should at least allow access by name, and for
parameter passing, require it.
I would like to to see a strong rationale for changing the style of the
library, in particular if it is only for certain input types and not others.
On 13 November 2009 at 11:13, Ott Toomet wrote:
| OK, so it works for me now. I changed RcppParams a little bit, so it can
| extract arbitrary list components (getValue member function) and it's
| components need not to be named ('named' member variable). It is also easy
| to extract components by position.
Ok, the way these things are often done is by patch against current
sources. Please work against the Subversion repository at R-Forge (which you
can check out anonymously), and provide a diff against these sources. Please
also patch the help pages (man/RcppParams.Rd) and other files such as tests
etc (not applicable).
| I would be happy to implement some of the stuff in a more polished way to
| the package but only if we can agree about what and how.
Yes, let's start with simple and well-defined changes and let's see how that goes.
| Best,
| Ott
|
| Below my modified class.
|
| class RcppParams {
| public:
| RcppParams(SEXP params);
| void checkNames(char *inputNames[], int len);
| bool exists(std::string name);
| double getDoubleValue(std::string name);
| int getIntValue(std::string name);
| std::string getStringValue(std::string name);
| bool getBoolValue(std::string name);
| RcppDate getDateValue(std::string name);
| RcppDatetime getDatetimeValue(std::string name);
| SEXP getValue(std::string name);
| SEXP getValue(int posn) { return VECTOR_ELT(_params,posn); };
Are you saying that your change is these two lines? But what about
error-checking?
What about my comments in earlier mail to you that you do not need 'get SEXP
from list' as you can simply pass more SEXP objects in the initial call from
R via .Call() ? It is not too polite to simply ignore questions and move on.
Romain and I also had discussions about possibly adding a new internal SEXP
representation. RcppTemplate has one, Rserve has another. If we do that than
this change would probably be a 'toSEXPtype' extractor.
| int size() { return Rf_length(_params); };
| bool isNamed() { return named; };
Who sets names? A diff to src/RcppParams.h and src/RcppParams.cpp would be
easier to analyse.
Regards, Dirk
|
| private:
| bool named;
| std::map<std::string, int> pmap;
| SEXP _params;
| };
--
Three out of two people have difficulties with fractions.
--
The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and privileged material.Any review, retransmission, dissemination or other use of,or taking of any action in reliance upon, this informationby persons or entities other than the intended recipientis prohibited.If you received this in error, please contact the senderand delete the material from any computer.
More information about the Rcpp-devel
mailing list