Re: [Rcpp-devel] Life-cycle of Rcpp::XPtr

2023-09-23 Thread Ralf Stubner
Hi Dirk,

> I had done some experiments with 'expanded finalizers' that use more logging
> (which I find quite convenient via `spdl` -- same nice spdlog interface now
> from R and C++) so you could add some display of the pointer address, check
> on nullness etc.
>
> I have done a bit more work using XPtr in the context of the tiledb (and the
> related, possibly upcoming tiledbsoma package not yet on CRAN) where I use an
> enum (which requires C++17 in the use I have there) to 'type tag' each
> external pointer and on each use check I have the correct type. I am not
> thinking to a simple unordered_map from enum to string to also make more
> informed errors (showing the type as string rather than enum int value) as
> well as maybe an enhanced show or print at the R level. I have long been
> meaning to farm that out into a new (simple) add-on package (see issue #1212)
> and should get on with that.  (The 'still somewhat raw' XPtr extension in
> tiledb is eg here:
> https://github.com/TileDB-Inc/TileDB-R/blob/1e7bd2fa4e54f3e152c4fec3a65343df49d3f525/src/libtiledb.h#L80-L160
> and the check_xptr_tag is then used throughout the files in src/.

Thanks! That does sound interesting. I think for my current use-case
the existing functionality is sufficient. But i will have a look at
these ideas.

Ralf
___
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] Life-cycle of Rcpp::XPtr

2023-09-23 Thread Ralf Stubner
On Sat, Sep 23, 2023 at 9:49 AM Simon Urbanek
 wrote:
>
> The copy constructor doesn't actually create a copy, it only acts as a 
> wrapper that preserves the same EXTPTR object, it is akin to increasing the 
> reference count, so the C++ class wrapped in the EXTPTR is only released when 
> the EXTPTR can be garbage-collected, i.e. all references are gone (including 
> all "copies").
> [Of course that is not true if you were to create two XPtrs with the same 
> pointer and a finalizer each, but that would be a bad idea, obviously].

Thanks Simon! This seems to be the behaviour I am looking for.

Ralf
___
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] Life-cycle of Rcpp::XPtr

2023-09-23 Thread Ralf Stubner
Hi everybody,

I have a question concerning the file-cycle of Rcpp::XPtr: Consider a
XPtr with the default delete finalizer wrapping some pointer. If I use
the copy constructor to create another XPtr, this is pointing at the
same underlying object as expected. What happens if one of these
pointers goes out of scope and is at some point garbage collected? Is
the underlying object deleted leaving the other XPtr with a broken
pointer? Or is the object protected by the existence of the other
pointer? From my experiments I have the impression that the latter is
the case, which would be the desired behaviour. But it would be nice
if one could be sure.

Thanks
Ralf
___
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] rcpp compile problem

2020-01-28 Thread Ralf Stubner
On Tue, Jan 28, 2020 at 10:04 AM Gerhard Boenisch
 wrote:
>
> Hi
>
> I am new to rcpp and am unable to compile code I know works. I must be doing 
> something stupid.
>
> I am using Windows (10).
>
> I have received the cpp source files for the BHPMF package. We want to make 
> the package work on the latest version of R.

I assume this refers to
https://cran.r-project.org/src/contrib/Archive/BHPMF/BHPMF_1.0.tar.gz,
right? Then this is actually off-topic on this list, since BHPMF does
not use Rcpp. The r-pkg-devel mailing list might be more appropriate.

> I am currently using R 3.4.4 (the last version BHPMF works).

I think you can work with a more recent version right away. Out of
curiosity I ran

R CMD check BHPMF_1.0.tar.gz

using current R 3.6.2. This command compiles and installs the package
and runs different checks on it. The result were two warnings:

* checking whether package ‘BHPMF’ can be installed ... WARNING
Found the following significant warnings:
  utillity.cpp:293:15: warning: ignoring return value of ‘int
fscanf(FILE*, const char*, ...)’, declared with attribute
warn_unused_result [-Wunused-result]
[...]
* checking for portable use of $(BLAS_LIBS) and $(LAPACK_LIBS) ... WARNING
  apparently using $(BLAS_LIBS) without following $(FLIBS) in ‘src/Makevars’

Warnings like this this are sufficient to have a package removed from
CRAN. They should be easy enough to fix, though.

cheerio
ralf
___
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] dmvnorm() of mvtnorm using RcppArmadillo

2019-12-19 Thread Ralf Stubner
On Thu, Dec 19, 2019 at 8:01 AM Shaami  wrote:

>   Environment pkg = Environment::namespace_env("mvtnorm");
>   Function dmvnorm = pkg["mvtnorm"];
>

There is no mvtnorm function in the mvtnorm package. You probably want to
dmvnorm function instead.

BTW, the mvtnorm package provides a C API for the dmvnorm function, c.f.
https://stackoverflow.com/a/51294364/8416610

cheerio
ralf
___
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] Runtime error from Rcpp::depends with gcc sanitizers

2019-02-12 Thread Ralf Stubner
Hi list,

I run into run-time errors when using rhub::check_with_sanitizers(),
which can be reproduced like this:

$ docker run -it --rm rhub/rocker-gcc-san bash
root@c56cfa20e903:/# RDscript -e "install.packages('Rcpp')"
[...]
root@c56cfa20e903:/# cat > foo.cpp
#include 
// [[Rcpp::depends(Matrix)]]

// [[Rcpp::export]]
int foo() { return 0; }

root@c56cfa20e903:/# RDscript -e "Rcpp::sourceCpp('foo.cpp')"
attributes.cpp:168:11: runtime error: load of value 104, which is not a
valid value for type 'bool'
attributes.cpp:168:11: runtime error: load of value 2, which is not a
valid value for type 'bool'

There is no error if I omit Rcpp::depends:

root@c56cfa20e903:/# cat > bar.cpp
#include 

// [[Rcpp::export]]
int foo() { return 0; }

root@c56cfa20e903:/# RDscript -e "Rcpp::sourceCpp('bar.cpp')"
root@c56cfa20e903:/#

These errors do not occur in the tests run by CRAN (or they are filtered
out there). Does anyone have an idea where this might come from and how
it could be fixed?

Thanks
Ralf

-- 
Ralf Stubner
Senior Software Engineer / Trainer

daqana GmbH
Dortustraße 48
14467 Potsdam

T: +49 331 23 61 93 11
F: +49 331 23 61 93 90
M: +49 162 20 91 196
Mail: ralf.stub...@daqana.com

Sitz: Potsdam
Register: AG Potsdam HRB 27966
Ust.-IdNr.: DE300072622
Geschäftsführer: Dr.-Ing. Stefan Knirsch, Prof. Dr. Dr. Karl-Kuno Kunze



signature.asc
Description: OpenPGP digital signature
___
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] Rcpp - libtorrent

2019-02-11 Thread Ralf Stubner
On 11.02.19 10:29, Morgan Morgan wrote:
> I use ubuntu and windows. But the idea would be to make the package
> available to all users including Mac OS.

I would start with Ubuntu, since there it should be sufficient to use

sudo apt-get install libtorrent-dev

together with

PKG_LDFLAGS=-ltorrent

in src/Makevars. After that I would focus on the functions to put into
the package. Once the package has a clearer shape, I would tackle the
cross-platform issues.

cheerio
ralf

-- 
Ralf Stubner
Senior Software Engineer / Trainer

daqana GmbH
Dortustraße 48
14467 Potsdam

T: +49 331 23 61 93 11
F: +49 331 23 61 93 90
M: +49 162 20 91 196
Mail: ralf.stub...@daqana.com

Sitz: Potsdam
Register: AG Potsdam HRB 27966
Ust.-IdNr.: DE300072622
Geschäftsführer: Dr.-Ing. Stefan Knirsch, Prof. Dr. Dr. Karl-Kuno Kunze



signature.asc
Description: OpenPGP digital signature
___
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] Fwd: Installing Rcpp and working a compilation with C++

2018-11-01 Thread Ralf Stubner
On 11/1/18 2:42 AM, Benjamin S. Levy wrote:
>> PKG_CXXFLAGS="-I/usr/local/lib/R/site-library/Rcpp/include" \
>> PKG_LIBS="-L/home/myDir/R/x86_64-pc-linux-gnu-library/3.5/Rcpp/libs
This looks fishy. For PKG_CXXFLAGS you say that Rcpp is installed in
/usr/local/lib/R/site-library/Rcpp/. For PKG_LIBS you use
/home/myDir/R/x86_64-pc-linux-gnu-library/3.5/Rcpp/. Where is it
actually installed?

Greetings
Ralf

-- 
Ralf Stubner
Senior Software Engineer / Trainer

daqana GmbH
Dortustraße 48
14467 Potsdam

T: +49 331 23 61 93 11
F: +49 331 23 61 93 90
M: +49 162 20 91 196
Mail: ralf.stub...@daqana.com

Sitz: Potsdam
Register: AG Potsdam HRB 27966
Ust.-IdNr.: DE300072622
Geschäftsführer: Dr.-Ing. Stefan Knirsch, Prof. Dr. Dr. Karl-Kuno Kunze



signature.asc
Description: OpenPGP digital signature
___
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] Populate a Matrix in Parallel (Text Version)

2018-09-28 Thread Ralf Stubner
Hi Joseph,

On 9/28/18 3:26 AM, Joseph Wood wrote:
> I understand that parallelism is not a magic wand. Have you read my
> original post? I have managed to parallelize generating permutations
> by taking advantage of the fact that I can generate the ith
> permutation via nthPerm. My question is about making this thread safe
> not if it is possible.

unfortunately, you messages are a bit long and contradictory. I had the
same reaction as Jeff when I read

>> My situation is fundamentally different. The algorithm that fills the
>> matrix does so in a way that relies on the previous row and more
[...]

If you have code that generates the n-th row based on some global input,
then the example I refered to would be the right starting point. It uses
global state (seed) and column indices to fill a matrix by column. It
does it for multiple columns together, since it is more efficient to
have one thread process multiple columns. However, the default grain
size for parallelFor is one, so it is easy to create one thread per
column and perform some action based on some global input and on the
column index:


#include 
// [[Rcpp::depends(RcppParallel)]]
#include 
// [[Rcpp::plugins(cpp11)]]

struct ParallelFill : public RcppParallel::Worker {
  RcppParallel::RMatrix output;
  RcppParallel::RVector global_input;

  ParallelFill(Rcpp::NumericMatrix output,
   Rcpp::NumericVector input) :
   output(output), global_input(input) {};

  std::vector create_column(std::size_t index) {
std::vector result(global_input.size());
std::transform(global_input.begin(),
   global_input.end(),
   result.begin(),
   [] (double a) {return a + index;});
return result;
  }

  // default grain size is 1, i.e. end == begin + 1
  void operator()(std::size_t begin, std::size_t end) {
std::vector column = create_column(begin);
std::copy(column.begin(), column.end(),
  output.begin() + begin * output.nrow());
  }
};

// [[Rcpp::export]]
Rcpp::NumericMatrix parallel_matrix(const int n,
Rcpp::NumericVector input) {
  Rcpp::NumericMatrix res(input.length(), n);
  ParallelFill parallelFill(res, input);
  RcppParallel::parallelFor(0,  n, parallelFill);
  return res;
}

/*** R
set.seed(42)
res <- parallel_matrix(8, runif(1e7))
head(res)
*/

All this is done *by column*, since matrices in R are stored that way.

cheerio
ralf




signature.asc
Description: OpenPGP digital signature
___
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] Populate a Matrix in Parallel (Text Version)

2018-09-26 Thread Ralf Stubner
I haven’t read your message in detail, but the second example from here might 
be helpful: 
https://cran.r-project.org/web/packages/dqrng/vignettes/parallel.html

There a matrix is filled in parallel by splitting the columns among the 
threads. Splitting by columns is helpful since matrices in R are stored that 
way. You could use the same method to obtain the transpose of your matrix. 

Greetings 
Ralf

— 
Ralf Stubner
Senior Software Engineer / Trainer
 
daqana GmbH
Dortustraße 48
14467 Potsdam
 
T: +49 331 23 70 81 66
F: +49 331 23 70 81 67
M: +49 162 20 91 196
 Mail: ralf.stub...@r-institute.com
 
Sitz: Potsdam
Register: AG Potsdam HRB 27966 P
Ust.-IdNr: DE300072622
Geschäftsführer: Prof. Dr. Dr. Karl-Kuno Kunze
 

> Am 26.09.2018 um 18:17 schrieb Joseph Wood :
> 
> As the subject states, this question is regarding populating a matrix
> in parallel. I am currently reading "C++ Concurrency in Action:
> Practical Multithreading" as I'd like to take some algorithms I have
> to the next level. I have looked at the RcppParallel package, but the
> features offered there do not seem to apply to this situation. I will
> explain my reasoning further down. First, we set up our scenario.
> 
>  1. We have an empty matrix with the number of rows equal to numRows
>  2. We are able to generate the ith row of the matrix at will
>  3. Our underlying subroutine populates the matrix from any
> particular starting point one by one.
> 
> This scenario easily extends to a parallel setup. We have each entry
> in our matrix being visited exactly one time by only one thread. The
> idea is that if we have m threads, we can split up the work so that
> each thread is responsible for populating roughly (numRows / m) number
> of rows of our matrix.
> 
> Here is a simplified example that represents my real situation (In my
> project I don't have the cpp11 plugin as I take care of this in
> Makevars file with CXX_STD = CXX11):
> 
> #include 
> #include 
> 
> // [[Rcpp::plugins(cpp11)]]
> 
> int myFactorial(int n) {
>int res = 1;
>for (int i = 1; i <= n; ++i)
>res *= i;
> 
>return res;
> }
> 
> std::vector nthPerm(int n, int index) {
>int temp = myFactorial(n);
>std::vector indexVec(n), res(n);
>std::iota(indexVec.begin(), indexVec.end(), 1);
> 
>for (int k = 0, r = n; k < n; ++k, --r) {
>temp /= r;
>int j = (int) index / temp;
>res[k] = indexVec[j];
>index -= (temp * j);
>indexVec.erase(indexVec.begin() + j);
>}
> 
>return res;
> }
> 
> // Simplified version for demonstration only. The real subroutines
> // that carry out this task are more complicated
> void PopulateMatrix(Rcpp::IntegerMatrix permuteMatrix,
>std::vector z, int count, int nRows, int n) {
>for (; count < nRows; ++count) {
>for (int j = 0; j < n; ++j)
>permuteMatrix(count, j) = z[j];
> 
>std::next_permutation(z.begin(), z.end());
>}
> }
> 
> // [[Rcpp::export]]
> SEXP ParallelPerms(int n, int userThrds = 0) {
>int nThreads = std::thread::hardware_concurrency() - 1;
>std::vector myThreads;
>nThreads = (userThrds > 0) ? std::min(userThrds, nThreads) : nThreads;
> 
>int step = 0, numRows = myFactorial(n);
>int stepSize = numRows / nThreads;
>int nextStep = stepSize;
>std::vector z(n);
>std::iota(z.begin(), z.end(), 1);
> 
>Rcpp::IntegerMatrix myMat = Rcpp::no_init_matrix(numRows, n);
> 
>for (std::size_t j = 0; j < (nThreads - 1); ++j) {
>myThreads.emplace_back(PopulateMatrix, std::ref(myMat), z,
> step, nextStep, n);
>step += stepSize;
>nextStep += stepSize;
>z = nthPerm(n, step);
>}
> 
>// Guarantee that we get all the rows. N.B. We are passing numRows
>// instead of nextStep... they aren't guaranteed to be the same
>myThreads.emplace_back(PopulateMatrix, std::ref(myMat), z, step,
> numRows, n);
> 
>for (auto& thr: myThreads)
>thr.join();
> 
>return myMat;
> }
> 
> I have read that Rcpp objects are not thread safe as they make
> unpredictable calls to the garbage collector
> (https://github.com/RcppCore/RcppParallel/issues/17), however Romain
> Francois states:
> 
> "As soon as you don't use references for Rcpp types, you are not safe.
> If you use references, it all depends on what you do with them."
> 
> I have a couple of questions regarding this.
> 
> My initial thought was I thought Rcpp objects were passed by reference
> by default. Secondly, if this isn't the case, is it as simple as
> adding an ampersand to all of my Rcpp objects in the function
> 

Re: [Rcpp-devel] Question on performance and strategy

2018-09-24 Thread Ralf Stubner
On 9/22/18 8:41 PM, Jordi Molins wrote:
> I have access to a machine (not a desktop) with quite a few CPUs and
> quite a few GPUs. So, if for example there are 100 CPU cores and 100,000
> GPU cores, I guess that I could do a foreach for these 100 CPU cores for
> an R function, and then if this R function calls RcppArrayFire,
> RcppArrayFire could call 1,000 GPU cores for each call, to make the
> whole 100,000 GPU cores, no? Or is everything more complex than that?
ArrayFire can make use of multiple GPUs [1]. I do not know if it is able
to treat them as one unit. I would expect that one has to do this more
explicitly, e.g. using an explicit loop and setting the device to be
used like here https://github.com/arrayfire/arrayfire-python/issues/165.

However, all this is not related to Rcpp.

Greetings
Ralf

[1] c.f. http://arrayfire.org/docs/group__device__mat.htm

-- 
Ralf Stubner
Senior Software Engineer / Trainer

daqana GmbH
Dortustraße 48
14467 Potsdam

T: +49 331 23 61 93 11
F: +49 331 23 61 93 90
M: +49 162 20 91 196
Mail: ralf.stub...@daqana.com

Sitz: Potsdam
Register: AG Potsdam HRB 27966 P
Ust.-IdNr.: DE300072622
Geschäftsführer: Prof. Dr. Dr. Karl-Kuno Kunze



signature.asc
Description: OpenPGP digital signature
___
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] Expose cpp class with built-in boost odeint to R

2018-09-17 Thread Ralf Stubner
On 15.09.2018 00:05, Simon Woodward wrote:
> My simulation model will be 1000+ lines of C++, this is a prototype, I 
> embedded the code inline to make it easier to post as a reprex to this forum.

A C++ file with a special /*** R ... */ comment would still be a minimal
example. Just look at the code RStudio produces by default when you
create a new C++ file. When you use Rcpp::sourceCpp() on that file, not
only the code is compiled and linked, but the R code within this special
comment is executed. RStudio does that by default when you source the
file, e.g. via C-S-Return.

> - do I need to worry about destructing my global variable my_spring (the 
> instance of my class)? If so, how do I do this? 

Global variables get destructed when the program ends. I would get rid
the global variable, making it local to the translation unit. One way to
achieve that would be an anonymous namespace.

> - for read/write efficiency, can/should I make a persistent link 
> (Rccp::XPtr?) between the my_spring.variable property and an object or 
> function in R? If so, how do I do this? Or is it better simply to copy-pass 
> the data when needed and let Rccp handle the conversion from 
> std::unordered_map to an R named vector?

I am not sure what you are trying to do here. But as a general rule: try
to write correct and working code first and do any performance
optimizations when you know where the bottlenecks are.

cheerio
ralf

-- 
Ralf Stubner
Senior Software Engineer / Trainer

daqana GmbH
Dortustraße 48
14467 Potsdam

T: +49 331 23 61 93 11
F: +49 331 23 61 93 90
M: +49 162 20 91 196
Mail: ralf.stub...@daqana.com

Sitz: Potsdam
Register: AG Potsdam HRB 27966 P
Ust.-IdNr.: DE300072622
Geschäftsführer: Prof. Dr. Dr. Karl-Kuno Kunze
___
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] Expose cpp class with built-in boost odeint to R

2018-09-14 Thread Ralf Stubner
On 14.09.2018 05:17, Simon Woodward wrote:
> I am developing a simulation model in C++ and I want to expose it to R for 
> testing. The model is in a C++ class and uses the boost::odeint library for 
> numerical integration. I am also using an unordered_map to expose the model 
> variables to the user.
> I am having some trouble exposing the class functionality to C++, either as 
> separate // [[Rcpp::export]] methods or using RCPP_MODULE. The following code 
> successfully instantiates the model and returns the unordered_map but crashes 
> Rcpp if I try to access the advance(t,dt) method.

What do you mean with "crashes Rcpp"? On my system it mearly gives a
compiler error:

/usr/include/c++/6/bits/stl_iterator_base_funcs.h: In instantiation of
‘void std::advance(_InputIterator&, _Distance) [with _InputIterator =
Rcpp::InputParameter; _Distance = Rcpp::InputParameter]’:


> # sample code embedded in an R script

With the given ratio of C++ to R code it would have been better to use a
C++ file with R code embedded via /*** R ... */.

> library(Rcpp)
> 
> Sys.setenv("PKG_CXXFLAGS"='-I"C:/boost/boost_1_66_0"')

The BH package can help with that:

  // [[Rcpp::depends(BH)]]

> sourceCpp(code='
>   #include 
>   #include 
>   #define BOOST_CONFIG_SUPPRESS_OUTDATED_MESSAGE
>   #include 
>   #include 
> 
>   // Enable C++11 via this plugin (Rcpp 0.10.3 or later)
>   // [[Rcpp::plugins(cpp11)]]
> 
>   using namespace std;

The above quoted error message indicates that your advance method and
std::advance are getting mixed up. Remove this "using namespace std;"
and handle to resulting errors by using "std::" or "using std::...;".

BTW, for larger pieces of code I would also get rid of "using namespace
Rcpp;".

cheerio
ralf

-- 
Ralf Stubner
Senior Software Engineer / Trainer

daqana GmbH
Dortustraße 48
14467 Potsdam

T: +49 331 23 61 93 11
F: +49 331 23 61 93 90
M: +49 162 20 91 196
Mail: ralf.stub...@daqana.com

Sitz: Potsdam
Register: AG Potsdam HRB 27966 P
Ust.-IdNr.: DE300072622
Geschäftsführer: Prof. Dr. Dr. Karl-Kuno Kunze



signature.asc
Description: OpenPGP digital signature
___
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] Rcpp unreachable when RInside+Hemi tryed to be compiled together

2018-05-18 Thread Ralf Stubner
On 18.05.2018 09:22, ExtremePasta wrote:
> using -Xcompiler and removing some flag from $(shell $(R_HOME)/bin/R CMD
> config CXXFLAGS) I tryed to make nvcc recognize all the gcc command but
> I don't know if this allow nvcc run it perfectly. When running "make"
> this is the error I get:
> 
> nvcc parallel_for.cpp --std=c++11 -I../ -I../../ -I/usr/share/R/include
> -I/home/pesco/R/x86_64-pc-linux-gnu-library/3.2/Rcpp/include
> -I/home/pesco/R/x86_64-pc-linux-gnu-library/3.2/RInside/include -g 
> -Xcompiler -fstack-protector-strong -Xcompiler -Wformat -Xcompiler
> -Wdate-time -Xcompiler -D_FORTIFY_SOURCE=2 -O3 -g -DDEBUG -G
> -D_FORCE_INLINES --expt-extended-lambda -x cu -o parallel_for_device
[...]> /tmp/tmpxft_0456_-10_parallel_for.o: nella funzione
> "Rcpp::Rstreambuf::xsputn(char const*, long)":
> /home/pesco/R/x86_64-pc-linux-gnu-library/3.2/Rcpp/include/Rcpp/iostream/Rstreambuf.h:56:
> riferimento non definito a "REprintf"

In the compiler/linker call you are missing at least something like
"-L/usr/lib/R/lib -lR", which is part of $(LDLIBS) via $(RLDFLAGS). Try
to include $(LDLIBS) in the command used for compilation and linking.

Greetings
Ralf

-- 
Ralf Stubner
Senior Software Engineer / Trainer

daqana GmbH
Dortustraße 48
14467 Potsdam

T: +49 331 23 70 81 66
F: +49 331 23 70 81 67
M: +49 162 20 91 196
Mail: ralf.stub...@daqana.com

Sitz: Potsdam
Register: AG Potsdam HRB 27966 P
Ust.-IdNr.: DE300072622
Geschäftsführer: Prof. Dr. Dr. Karl-Kuno Kunze



signature.asc
Description: OpenPGP digital signature
___
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] Getting different build commands on Linux vs. Mac OS

2018-04-30 Thread Ralf Stubner

> Am 30.04.2018 um 23:42 schrieb Evan Biederstedt :
> 
> @Ralf
> 
> > I had not installed the necessary C library, so unsurprisingly the 
> > compilation step already failed. What I find interesting is that in my case 
> > "-std=gnu++11“ and "-I../inst/include/" are present in the command line 
> > options for clang++. These are also missing from what you quoted and are 
> > also a consequence of src/Makevars. It almost looks as if this file got 
> > lost on your macOS box …
> 
> InterestingI'm not sure what to make of this of course, but it would be 
> interesting if it was only happening on this macbook. Perhaps OS version or 
> brew could be to blame? I'm not sure what else would be "special" about this 
> macbook

On my side that would be
• macOS high Sierra
• CRAN R 3.4.4
• clang and gfortran as recommended by CRAN
• brew is installed but I do not see how it enters the picture 

Greetings 
Ralf 

smime.p7s
Description: S/MIME cryptographic signature
___
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] Getting different build commands on Linux vs. Mac OS

2018-04-30 Thread Ralf Stubner

> Am 30.04.2018 um 21:01 schrieb Evan Biederstedt :
> @Ralf
> 
> > You can change the used compiler for *your* system via ~/.R/Makevars, 
> > though. From my point of view that is a (short-time) workaround only. You 
> > have to figure out why clang does not like your package/library.
> 
> I've yet to test changing the compiler in ~/.R/Makevars. However, it's not 
> clear to me why this would be a short-term solution. Could you clarify why 
> using g++ instead of clang would be a problem gong forwards?

Because clang is the default compiler for R on MacOS. So you would make it 
difficult for other people (let alone CRAN) to make use of the package. 
However, I think there is something wrong about your macOS machine. I have just 
tried to compile your package on a macOS machine that I have access to, and I 
got quite different results:

$ R CMD INSTALL bambi_1.0.tar.gz 
* installing to library 
‘/Library/Frameworks/R.framework/Versions/3.4/Resources/library’
* installing *source* package ‘bambi’ ...
** libs
/usr/local/clang4/bin/clang++ -std=gnu++11 
-I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I../inst/include/ 
-I"/Library/Frameworks/R.framework/Versions/3.4/Resources/library/Rcpp/include" 
-I/usr/local/include   -fPIC  -Wall -g -O2 -c RcppExports.cpp -o RcppExports.o
/usr/local/clang4/bin/clang++ -std=gnu++11 
-I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I../inst/include/ 
-I"/Library/Frameworks/R.framework/Versions/3.4/Resources/library/Rcpp/include" 
-I/usr/local/include   -fPIC  -Wall -g -O2 -c bambi.cpp -o bambi.o
bambi.cpp:7:14: fatal error: 'bam_lmdb.h' file not found
#include "bam_lmdb.h"
 ^~~~
1 error generated.
make: *** [bambi.o] Error 1
ERROR: compilation failed for package ‘bambi’
* removing 
‘/Library/Frameworks/R.framework/Versions/3.4/Resources/library/bambi’

I had not installed the necessary C library, so unsurprisingly the compilation 
step already failed. What I find interesting is that in my case "-std=gnu++11“ 
and "-I../inst/include/" are present in the command line options for clang++. 
These are also missing from what you quoted and are also a consequence of 
src/Makevars. It almost looks as if this file got lost on your macOS box …

Greetings
Ralf

___
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] Getting different build commands on Linux vs. Mac OS

2018-04-30 Thread Ralf Stubner
On 30.04.2018 12:48, Evan Biederstedt wrote:
> How do I direct the Makevars to use g++ and give me the "correct" build
> as I see on Linux? `CXX=g++` or `CXX=/usr/local/bin/g++` doesn't appear
> to work. 

Quoting Duncan Murdoch in
https://stat.ethz.ch/pipermail/r-package-devel/2017q4/002087.html:

> According to section 1.2.1 "Using Makevars" in Writing R Extensions,
> R_HOME/etcR_ARCH/Makeconf is included after Makevars, so what you're
> seeing is by design. I believe this is so that packages are built with
> tools compatible with those that built R. (Remember, packages are
> designed for distribution to diverse systems.)

So you might change various flags within src/Makevars via for example
PKG_CXXFLAGS, but you cannot overwrite CXXFLAGS or CXX itself. And there
is no PKG_CXX. You can change the used compiler for *your* system via
~/.R/Makevars, though. From my point of view that is a (short-time)
workaround only. You have to figure out why clang does not like your
package/library.

Greetings
Ralf


-- 
Ralf Stubner
Senior Software Engineer / Trainer

daqana GmbH
Dortustraße 48
14467 Potsdam

T: +49 331 23 70 81 66
F: +49 331 23 70 81 67
M: +49 162 20 91 196
Mail: ralf.stub...@daqana.com

Sitz: Potsdam
Register: AG Potsdam HRB 27966 P
Ust.-IdNr.: DE300072622
Geschäftsführer: Prof. Dr. Dr. Karl-Kuno Kunze



smime.p7s
Description: S/MIME Cryptographic Signature
___
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] Combining C++ interface and exported function name with dot

2018-04-17 Thread Ralf Stubner
Hi,

I am developing a package where I would like to combine two Rcpp
Attribute features:
* Automatically providing a C++ interface
* Renaming the exported function in R to contain a dot

My current attempts at doing so result in a run-time error. Steps to
reproduce:

* create an new package with Rcpp::Rcpp.package.skeleton()
* change src/rcpp_hello_world.cpp to rename the exported function and
create both R and C++ interfaces:

// [[Rcpp::interfaces(r, cpp)]]
#include 
using namespace Rcpp;

// [[Rcpp::export(hello.world)]]
List rcpp_hello_world() {

CharacterVector x = CharacterVector::create( "foo", "bar" )  ;
NumericVector y   = NumericVector::create( 0.0, 1.0 ) ;
List z= List::create( x, y ) ;

return z ;
}

* build and install the package
* reference the function from C++:

// [[Rcpp::depends(anRpackage)]]
#include 
#include 

// [[Rcpp::export]]
Rcpp::List wrapper() {
  return anRpackage::hello_world();
}
/*** R
wrapper()
*/

If I rename the function to 'hello_world', this compiles and runs fine.
If I rename the function to 'hello.world', it still compiles but fails
to run:

> wrapper()
Error in wrapper() :
  Function not exported: C++ function with signature
'List(*hello_world)()' not found in anRpackage.


Is there a way to combine these two features?

Thanks
Ralf

-- 
Ralf Stubner
Senior Software Engineer / Trainer

daqana GmbH
Dortustraße 48
14467 Potsdam

T: +49 331 23 70 81 66
F: +49 331 23 70 81 67
M: +49 162 20 91 196
Mail: ralf.stub...@daqana.com

Sitz: Potsdam
Register: AG Potsdam HRB 27966 P
Ust.-IdNr.: DE300072622
Geschäftsführer: Prof. Dr. Dr. Karl-Kuno Kunze



smime.p7s
Description: S/MIME Cryptographic Signature
___
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] Modules + Attributes for extensions

2018-03-06 Thread Ralf Stubner
On 06.03.2018 00:08, fernandohtol...@gmail.com wrote:
> I
> will also appreciate if someone point me an R package in which custom
> as/wrap are defined!

The reference: http://dirk.eddelbuettel.com/code/rcpp/Rcpp-extending.pdf
Also very useful:
http://gallery.rcpp.org/articles/custom-templated-wrap-and-as-for-seamingless-interfaces/

Simple example: RcppBDT
More complex examples: RcppArmadillo, RcppEigen, RcppGSL

Greetings
Ralf

-- 
Ralf Stubner
Senior Software Engineer / Trainer

R Institute GmbH
Dortustraße 48
14467 Potsdam

T: +49 331 23 70 81 66
F: +49 331 23 70 81 67
M: +49 162 20 91 196

Mail: ralf.stub...@r-institute.com

Sitz: Potsdam
Register: AG Potsdam HRB 27966 P
Ust.-IdNr.: DE300072622
Geschäftsführer: Prof. Dr. Dr. Karl-Kuno Kunze



smime.p7s
Description: S/MIME Cryptographic Signature
___
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