Re: [Rcpp-devel] g++ flags
Hi Gabor, Looks like it was a bug on our end -- R-exts specifies that USE_CXX1X should be set to any value; we try to set it to nothing (ie, define it but leave it empty) but apparently that is not accepted. I just pushed a bug fix to GitHub and it works on my Windows VM; can you give it another shot? Thanks, Kevin On Tue, May 6, 2014 at 9:09 PM, Gabor Grothendieck wrote: > On Windows with R 3.1 I installed the latest Rcpp from github and did > the following but the compliation gave an error which was was due to > the C++11 constructs. If I rerun it but uncomment the Sys.setenv line > then it works. What do I do to get the cpp11 attribute to work? > > library(Rcpp) > # Sys.setenv("PKG_CXXFLAGS"="-std=c++0x") > cat(' > // [[Rcpp::plugins("cpp11")]] > // [[Rcpp::export]] > int useCpp11() { > auto x = 10; > return x; > } > ', file = "testauto.cpp") > sourceCpp("testauto.cpp") > > On Wed, Apr 30, 2014 at 11:12 AM, Dirk Eddelbuettel wrote: >> >> On 30 April 2014 at 10:05, Dirk Eddelbuettel wrote: >> | >> | On 30 April 2014 at 10:41, JJ Allaire wrote: >> | | I think that might be overkill (or something that we can do later if >> users ask >> | | for it). >> | >> | It is a one-liner, and it just sits there to be used, like OpenMP plugin. >> | >> | So in that sense it doesn't hurt, and it may yet help those for which both >> R >> | < 3.1.0 and Windows are true. >> >> Actually, as Gabor points out, where 'R < 3.1.0' and 'g++ < 4.7' which may >> also be a bunch of servers running older RHEL or Ubuntu LTS. >> >> Dirk >> >> -- >> Dirk Eddelbuettel | e...@debian.org | http://dirk.eddelbuettel.com >> ___ >> Rcpp-devel mailing list >> Rcpp-devel@lists.r-forge.r-project.org >> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel > > > > -- > Statistics & Software Consulting > GKX Group, GKX Associates Inc. > tel: 1-877-GKX-GROUP > email: ggrothendieck at gmail.com > ___ > Rcpp-devel mailing list > Rcpp-devel@lists.r-forge.r-project.org > https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel ___ Rcpp-devel mailing list Rcpp-devel@lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
Re: [Rcpp-devel] g++ flags
On Windows with R 3.1 I installed the latest Rcpp from github and did the following but the compliation gave an error which was was due to the C++11 constructs. If I rerun it but uncomment the Sys.setenv line then it works. What do I do to get the cpp11 attribute to work? library(Rcpp) # Sys.setenv("PKG_CXXFLAGS"="-std=c++0x") cat(' // [[Rcpp::plugins("cpp11")]] // [[Rcpp::export]] int useCpp11() { auto x = 10; return x; } ', file = "testauto.cpp") sourceCpp("testauto.cpp") On Wed, Apr 30, 2014 at 11:12 AM, Dirk Eddelbuettel wrote: > > On 30 April 2014 at 10:05, Dirk Eddelbuettel wrote: > | > | On 30 April 2014 at 10:41, JJ Allaire wrote: > | | I think that might be overkill (or something that we can do later if > users ask > | | for it). > | > | It is a one-liner, and it just sits there to be used, like OpenMP plugin. > | > | So in that sense it doesn't hurt, and it may yet help those for which both R > | < 3.1.0 and Windows are true. > > Actually, as Gabor points out, where 'R < 3.1.0' and 'g++ < 4.7' which may > also be a bunch of servers running older RHEL or Ubuntu LTS. > > Dirk > > -- > Dirk Eddelbuettel | e...@debian.org | http://dirk.eddelbuettel.com > ___ > Rcpp-devel mailing list > Rcpp-devel@lists.r-forge.r-project.org > https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com ___ Rcpp-devel mailing list Rcpp-devel@lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
[Rcpp-devel] New features in Rcpp
Hi everyone, Two features have been committed to the master branch of Rcpp on GitHub (https://github.com/RcppCore/Rcpp): 1. The ListOf class These function like R lists, under the assumption that each element of that list is of type T. This should allow you to write code like: typedef ListOf NVList; double add_first_three(NVList x) { return x[0] + x[1] + x[2]; } Any Rcpp container should fit in the ListOf class, and it is possible to nest them as well (ListOf< ListOf<...> >). 2. Warnings for implicit conversions You can now ask Rcpp to throw a warning if an implicit conversion is done by using #define RCPP_WARN_ON_COERCE before #include . With this, Rcpp will now throw a warning on implicit conversions -- for example, with NumericVector implicit_conv(SEXP x) { return x; } implicit_conv(1) is okay, but implicit_conv(1L) throws a warning, stating: Warning message: In implicit_conv(1L) : coerced object from 'integer' to 'double' This should help users of Rcpp avoid common bugs when attempting to modify an object in place, but automatic conversion has caused them to modify a (temporary, copied) version of that object. We are considering making this the default behavior in the future -- any thoughts? I would greatly appreciate tests and comments, especially for the ListOf class. (See: https://github.com/RcppCore/Rcpp/blob/master/inst/include/Rcpp/vector/ListOf.h) Thanks, Kevin ___ Rcpp-devel mailing list Rcpp-devel@lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
Re: [Rcpp-devel] How to define a function called when R exited
I believe you're looking for `.Last`. Unfortunately there's no way to set `on.exit(...)` for the global environment. >From the ?quit documentation: Immediately before terminating, .Last() is executed if the function .Last exists and runLast is true. If in interactive use there are errors in the .Last function, control will be returned to the command prompt, so do test the function thoroughly. There is a system analogue, .Last.sys(), which is run after .Last() if runLast is true. Exactly what happens at termination of an R session depends on the platform and GUI interface in use. A typical sequence is to run .Last() and .Last.sys() (unless runLast is false), to save the workspace if requested (and in most cases also to save the session history: see savehistory), then run any finalizers (see reg.finalizer) that have been set to be run on exit, close all open graphics devices, remove the session temporary directory and print any remaining warnings (e.g. from .Last() and device closure). Jamie Olson On Tue, May 6, 2014 at 12:53 PM, Jerome MARQUET wrote: > Hello, > > I am building a package "myModule" and would like to define a function that > will be called when R is exited. > > So I defined a function > > RcppExport void R_unload_mlxComputeR(DllInfo *info) > { > // Do sthg > } > > > and I observe that it is called when dyn.unload(myModule) is called. But the > function is not called when R is exited. I wonder if there is a similar > function (like R_exit_packgName or R_quit_packageName) that is called when R > is exited ? > > ___ > Rcpp-devel mailing list > Rcpp-devel@lists.r-forge.r-project.org > https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel ___ Rcpp-devel mailing list Rcpp-devel@lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
[Rcpp-devel] How to define a function called when R exited
Hello, I am building a package "myModule" and would like to define a function that will be called when R is exited. So I defined a function /RcppExport void R_unload_mlxComputeR(DllInfo *info)// //{// //// Do sthg// //}// / and I observe that it is called when dyn.unload(myModule) is called. But the function is not called when R is exited. I wonder if there is a similar function (like R_exit_packgName or R_quit_packageName) that is called when R is exited ? ___ Rcpp-devel mailing list Rcpp-devel@lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
Re: [Rcpp-devel] Questions on extending Rcpp wrap and as with templates
Hi Romain, You are correct. I have changed to specializations as below. However, as to the return type, are you saying the header file then also becomes RcppExport std::vector< TimedOptDouble > GetSunPositions(SEXP a) instead of RcppExport SEXP GetSunPositions(SEXP a) ? Or do I leave the header unchanged and just change the return type of the implementation? In terms of the second point, I use OptDouble a lot (e.g. boost::optional), which converts to a double with double ToDouble(OptDouble const& in) { return in ? *in : R_NaReal; } unfortunately that means that all the nice semantics available to me in Rcpp, e.g. Named("Results")=std::list, or std::vector, or std::vector > have all become unavailable as I always use OptDouble instead of double. Is it really that much hassle for me to add boost::optional to the internal handling? Thank you Florian On Tue, May 6, 2014 at 9:10 AM, Romain Francois wrote: > > Le 6 mai 2014 à 08:45, Florian Burkart a > écrit : > > Hi everyone (and Dirk), > > Second attempt on corrected email list. > > I have been trying to extend Rcpp with my own wrap and as templates. > > Two issues: > > 1) I need to explicitly call wrap. Is that expected? > > So for example I wrote this specialization: > > > This is not a specialization, just another overload. You need to write a > specialization, as in: > > namespace Rcpp{ > template<> SEXP wrap > > (std::vector const& entries) { … } > } > > template<> SEXP Rcpp::wrap(std::vector const& entries) { > std::vector sec_times; > std::vector doubles; > for(auto const& entry : entries) > { > sec_times.push_back(entry.GetTime().Seconds()); > TimedOptDouble::OptDouble opt_double(entry.GetOptDouble()); > if(opt_double) > doubles.push_back(*opt_double); > else > doubles.push_back(R_NaReal); > } > return List::create( > Named( "Time" ) = sec_times, > Named( "Value" ) = doubles); > } > > First of all, this returns what I believe to be a Rcpp::List object, which > seems to be converted implicitly to a SEXP. This is the typical behaviour I > know. > > > Unfortunately, when making use of this template, it doesn't work > implicitly, but I need to explicitly call it. > > So for example > > SEXP GetSunPositions(SEXP a) { > std::vector sun_positions; > ... > return wrap(sun_positions); > } > > works, where as > > return sun_positions; > > as last line doesn't. Am I doing something wrong here? I did do the > declaration before including . > > > This should work if you return a std::vector< TimedOptDouble > from your > function, as in: > > std::vector< TimedOptDouble > GetSunPositions(SEXP a) { … } > > 2) How to make as work for own types in containers > > The other way around, one can return a std::vector implicitly, but > how do I return std::vector? I tried to define > > template<> MyType as(SEXP); > > But that didn't help, e.g. I had to write my own > > template<> std::vector as(SEXP); > > > This is the easiest way. A more general way would need you to express how > to handle containers of MyType, but that requires defining some traits > classes etc … not sure it is worth the effort. > > But again, you’d need to actually write a specialization: template<> > std::vector as< std::vector > (SEXP); > > Romain > > > Thanks for help > Florian > ___ > Rcpp-devel mailing list > Rcpp-devel@lists.r-forge.r-project.org > https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel > > > ___ Rcpp-devel mailing list Rcpp-devel@lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
Re: [Rcpp-devel] How to create list of list without known structure
Perfect, thank you On Tue, May 6, 2014 at 1:01 PM, Romain Francois wrote: > > Le 6 mai 2014 à 09:35, Florian Burkart a > écrit : > > > Hi, > > > > I have been creating lists of lists with > > > > return Rcpp::List::create(Rcpp::Named("vec") = someVector, > > Rcpp::Named("lst") = someList, > > Rcpp::Named("vec2") = someOtherVector); > > > > or to follow Romain: > > > > using namespace Rcpp ; > > return List::create( > >_["vec"] = someVector, > >_["lst"] = someList, > >_["vec2"] = someOtherVector > > ) ; > > > > But how do I convert the following into a list of lists? > > > > std::vector m_column_headers; > > std::vector > m_vectors_of_values; > > You probably just need to know about .names() =, i.e. something like this > should do: > > List values = wrap(m_vectors_of_values) ; > values.names() = m_column_headers ; > > FWIW, in Rcpp11, you could use structure, e.g. : > > List values = structure( m_vectors_of_values, _["names"] = > m_column_headers ) ; > > Romain ___ Rcpp-devel mailing list Rcpp-devel@lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
Re: [Rcpp-devel] Save objects across sessions
On 6 May 2014 at 09:41, soeren.vo...@posteo.ch wrote: | Hello | | I am trying to enhance my enhance my Rcpp class with the functionality to | be saved across R sessions. For convenience reasons I would like to do that | in R, using the ReferenceClass's S4 member function 'finalize()'. My plan You talk about "your Rcpp class" and about RefClass / S4. Did you set up your object as an S4 or RefClass object? You could but you don't have to. | is to simply save all object's fields (vectors of various types) to a | special list (with a special class name), remove the Rcpp object, and save Serializing / saving all content is a good plan. But I am not sure what "remove the Rcpp object" is supposed to say. | the plain R object instead. Would that work/be a good option? In | particular, what happens on the C++ side if I call rm(reference_object)? Rcpp objects are R objects. They have the same behaviour as rm() for R objects: reference counting, and gc() effects only if nothing else depends on them (ie zero refcount). [ I am simplyfying here but that is the basic story. ] | Would that remove the C++ side and free its memory? And how can the reverse It depends. It can. [ I think we discuss that a little in the context of modules. Your Rcpp objects can have finalizers. Else it is standard C++ behaviour. ] | be accomplished, that is, if an object (identified by its class name) is | loaded from a previous session, rebuild the C++ side and form the original | reference object? There is a lot in this email, but it is a little muddled (and it is early in the day here and I did not yet have that much coffee, but I did have a morning run ...) Conceptually, if it helped, you could think about -- copying all content into an object you serialize (eg an R object for which you use save() or writeRDS()) -- creating the reverse to create an object 'factory' that creates an instance of your Rcpp object given an R object. The basic difficulty with more complicated Rcpp objects is that they are dynamic objects which 'hang' at a semi-random memory location, and on recreation you will have a different location. That made just calling save() impossible. And this was discussed (without a generic solution as there probably isn;t one) here in the past. Just FYI you could also look into other serilization approaches as eg in RProtoBuf, see our vignette / paper at http://arxiv.org/abs/1401.7372 But the overall topic is not trivial. Maybe try a simplification / problem subset first. Hope this helps, Dirk | | Sort of finalising: | | | x = new( 'Rcpp_Myclass' ) | x$finalize() calls: | x_list = make_my_special_list( x ) | rm( x ) | and then the system calls: | gc() | | | Sort of loading: | | | start_function_?() calls: | x_lists = look_if_there_is_some_x_lists() | for every x_list in x_lists: | name = name_of(x_list) | name = new( 'Rcpp_Myclass' ) | name$assign_values_from_x_list() | | | Thank you for help. | | Bests | Sören | | ___ | Rcpp-devel mailing list | Rcpp-devel@lists.r-forge.r-project.org | https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel -- Dirk Eddelbuettel | e...@debian.org | http://dirk.eddelbuettel.com ___ Rcpp-devel mailing list Rcpp-devel@lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
Re: [Rcpp-devel] How to create list of list without known structure
Le 6 mai 2014 à 09:35, Florian Burkart a écrit : > Hi, > > I have been creating lists of lists with > > return Rcpp::List::create(Rcpp::Named("vec") = someVector, > Rcpp::Named("lst") = someList, > Rcpp::Named("vec2") = someOtherVector); > > or to follow Romain: > > using namespace Rcpp ; > return List::create( >_["vec"] = someVector, >_["lst"] = someList, >_["vec2"] = someOtherVector > ) ; > > But how do I convert the following into a list of lists? > > std::vector m_column_headers; > std::vector > m_vectors_of_values; You probably just need to know about .names() =, i.e. something like this should do: List values = wrap(m_vectors_of_values) ; values.names() = m_column_headers ; FWIW, in Rcpp11, you could use structure, e.g. : List values = structure( m_vectors_of_values, _["names"] = m_column_headers ) ; Romain ___ Rcpp-devel mailing list Rcpp-devel@lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
Re: [Rcpp-devel] How to create list of list without known structure
Hi Florian, On 6 May 2014 at 09:35, Florian Burkart wrote: | Hi, | | I have been creating lists of lists with | | return Rcpp::List::create(Rcpp::Named("vec") = someVector, | Rcpp::Named("lst") = someList, | Rcpp::Named("vec2") = someOtherVector); Yes, it is a very common idiom as lists are the R structure used for nesting object with varying types or sizes. | or to follow Romain: | | using namespace Rcpp ; | return List::create( | _["vec"] = someVector, | _["lst"] = someList, | _["vec2"] = someOtherVector | ) ; | | But how do I convert the following into a list of lists? | | std::vector m_column_headers; | std::vector > m_vectors_of_values; You probably have to copy at some point. You could also use Rcpp types as the first (std::vector) could be an Rcpp::CharacterVector (which is a vector of strings, not single char); the second could be a Rcpp::NumericMatrix. There is some support for as<> and wrap() between these, but there is no function doing magic of the 'here, just convert these random two types I listed'. It all depends. Hope this helps, Dirk -- Dirk Eddelbuettel | e...@debian.org | http://dirk.eddelbuettel.com ___ Rcpp-devel mailing list Rcpp-devel@lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
[Rcpp-devel] Save objects across sessions
Hello I am trying to enhance my enhance my Rcpp class with the functionality to be saved across R sessions. For convenience reasons I would like to do that in R, using the ReferenceClass's S4 member function 'finalize()'. My plan is to simply save all object's fields (vectors of various types) to a special list (with a special class name), remove the Rcpp object, and save the plain R object instead. Would that work/be a good option? In particular, what happens on the C++ side if I call rm(reference_object)? Would that remove the C++ side and free its memory? And how can the reverse be accomplished, that is, if an object (identified by its class name) is loaded from a previous session, rebuild the C++ side and form the original reference object? Sort of finalising: x = new( 'Rcpp_Myclass' ) x$finalize() calls: x_list = make_my_special_list( x ) rm( x ) and then the system calls: gc() Sort of loading: start_function_?() calls: x_lists = look_if_there_is_some_x_lists() for every x_list in x_lists: name = name_of(x_list) name = new( 'Rcpp_Myclass' ) name$assign_values_from_x_list() Thank you for help. Bests Sören ___ Rcpp-devel mailing list Rcpp-devel@lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
[Rcpp-devel] How to create list of list without known structure
Hi, I have been creating lists of lists with return Rcpp::List::create(Rcpp::Named("vec") = someVector, Rcpp::Named("lst") = someList, Rcpp::Named("vec2") = someOtherVector); or to follow Romain: using namespace Rcpp ; return List::create( _["vec"] = someVector, _["lst"] = someList, _["vec2"] = someOtherVector ) ; But how do I convert the following into a list of lists? std::vector m_column_headers; std::vector > m_vectors_of_values; Thank you, Florian ___ Rcpp-devel mailing list Rcpp-devel@lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
Re: [Rcpp-devel] Questions on extending Rcpp wrap and as with templates
Le 6 mai 2014 à 08:45, Florian Burkart a écrit : > Hi everyone (and Dirk), > > Second attempt on corrected email list. > > I have been trying to extend Rcpp with my own wrap and as templates. > > Two issues: > > 1) I need to explicitly call wrap. Is that expected? > > So for example I wrote this specialization: This is not a specialization, just another overload. You need to write a specialization, as in: namespace Rcpp{ template<> SEXP wrap > (std::vector const& entries) { … } } > template<> SEXP Rcpp::wrap(std::vector const& entries) { > std::vector sec_times; > std::vector doubles; > for(auto const& entry : entries) > { > sec_times.push_back(entry.GetTime().Seconds()); > TimedOptDouble::OptDouble opt_double(entry.GetOptDouble()); > if(opt_double) > doubles.push_back(*opt_double); > else > doubles.push_back(R_NaReal); > } > return List::create( > Named( "Time" ) = sec_times, > Named( "Value" ) = doubles); > } > > First of all, this returns what I believe to be a Rcpp::List object, which > seems to be converted implicitly to a SEXP. This is the typical behaviour I > know. > > Unfortunately, when making use of this template, it doesn't work implicitly, > but I need to explicitly call it. > > So for example > > SEXP GetSunPositions(SEXP a) { > std::vector sun_positions; > ... > return wrap(sun_positions); > } > > works, where as > > return sun_positions; > > as last line doesn't. Am I doing something wrong here? I did do the > declaration before including . This should work if you return a std::vector< TimedOptDouble > from your function, as in: std::vector< TimedOptDouble > GetSunPositions(SEXP a) { … } > 2) How to make as work for own types in containers > > The other way around, one can return a std::vector implicitly, but > how do I return std::vector? I tried to define > > template<> MyType as(SEXP); > > But that didn't help, e.g. I had to write my own > > template<> std::vector as(SEXP); This is the easiest way. A more general way would need you to express how to handle containers of MyType, but that requires defining some traits classes etc … not sure it is worth the effort. But again, you’d need to actually write a specialization: template<> std::vector as< std::vector > (SEXP); Romain > Thanks for help > > Florian > ___ > Rcpp-devel mailing list > Rcpp-devel@lists.r-forge.r-project.org > https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel ___ Rcpp-devel mailing list Rcpp-devel@lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel