Skip to content

[Rcpp-devel] rcpp 0.10 on mac error with sourceCpp

10 messages · JJ Allaire, Jiqiang Guo, Dirk Eddelbuettel

#
I tried the example of sourceCpp on Mac mountain lion with R 2.15.1
with the following error (I hit the similar error in using RStan as
well).
+        #include <Rcpp.h>
+
+        // [[Rcpp::export]]
+        int fibonacci(const int x) {
+          if (x == 0) return(0);
+          if (x == 1) return(1);
+          return (fibonacci(x - 1)) + fibonacci(x - 2);
+        }'
+      , verbose = TRUE)

Generated Rcpp module declaration:
--------------------------------------------------------

RCPP_MODULE(sourceCpp_72196) {
    Rcpp::function("fibonacci", &fibonacci,
Rcpp::List::create(Rcpp::Named("x")));
}

Building shared library
--------------------------------------------------------

DIR: /var/folders/vs/tzgx0z_s0zvgg15pw84b93km0000gn/T//RtmpuSV7dx/sourcecpp_12a13a02b8d4

Error in tools:::file_path_as_absolute(base:::system.file(..., package
= "Rcpp")) :
  file '' does not exist
R version 2.15.1 (2012-06-22)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] tools     stats     graphics  grDevices utils     datasets
methods   base

other attached packages:
[1] Rcpp_0.10.0


===
Another place:

Error in tools:::file_path_as_absolute(base:::system.file(..., package
= "Rcpp")) :
  file '' does not exist
Calls: stan_model ... <Anonymous> -> RcppLdPath -> Rcpp.system.file ->
<Anonymous>
Execution halted

--
Jiqiang
#
On Thu, Nov 15, 2012 at 1:20 PM, Jiqiang Guo <guojq28 at gmail.com> wrote:

            
I think the common problem here might be whether R_ARCH is set correctly.
On the Mac R_ARCH needs to be set in order for R CMD SHLIB, which is used
by both sourceCpp and RStan, to work.

For 64-bit Macs this value would be:

R_ARCH=/x86_64

What is R_ARCH set to in your session?

J.J.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20121115/ee2eaf9b/attachment.html>
#
Thanks.

But I am using R from command line, and I think it is set correctly:
[1] "/x86_64"

--
Jiqiang
On Thu, Nov 15, 2012 at 1:30 PM, JJ Allaire <jj.allaire at gmail.com> wrote:
#
On 15 November 2012 at 13:20, Jiqiang Guo wrote:
| I tried the example of sourceCpp on Mac mountain lion with R 2.15.1
| with the following error (I hit the similar error in using RStan as
| well).
| 
| > library(Rcpp)
| > require(Rcpp)
| >
| >      sourceCpp(code='

Operator error:  sourceCpp() takes a filename.  cppFunction() takes a
"program in a string" a la cxxfunction()

Dirk


| +        #include <Rcpp.h>
| +
| +        // [[Rcpp::export]]
| +        int fibonacci(const int x) {
| +          if (x == 0) return(0);
| +          if (x == 1) return(1);
| +          return (fibonacci(x - 1)) + fibonacci(x - 2);
| +        }'
| +      , verbose = TRUE)
| 
| Generated Rcpp module declaration:
| --------------------------------------------------------
| 
| RCPP_MODULE(sourceCpp_72196) {
|     Rcpp::function("fibonacci", &fibonacci,
| Rcpp::List::create(Rcpp::Named("x")));
| }
| 
| Building shared library
| --------------------------------------------------------
| 
| DIR: /var/folders/vs/tzgx0z_s0zvgg15pw84b93km0000gn/T//RtmpuSV7dx/sourcecpp_12a13a02b8d4
| 
| Error in tools:::file_path_as_absolute(base:::system.file(..., package
| = "Rcpp")) :
|   file '' does not exist
| > sessionInfo()
| R version 2.15.1 (2012-06-22)
| Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)
| 
| locale:
| [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
| 
| attached base packages:
| [1] tools     stats     graphics  grDevices utils     datasets
| methods   base
| 
| other attached packages:
| [1] Rcpp_0.10.0
| 
| 
| ===
| Another place:
| 
| Error in tools:::file_path_as_absolute(base:::system.file(..., package
| = "Rcpp")) :
|   file '' does not exist
| Calls: stan_model ... <Anonymous> -> RcppLdPath -> Rcpp.system.file ->
| <Anonymous>
| Execution halted
| 
| --
| Jiqiang
| _______________________________________________
| Rcpp-devel mailing list
| Rcpp-devel at lists.r-forge.r-project.org
| https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
#
Thanks.

The same error if I use cppFunction thought the example in sourceCpp
use a string of c++ code passed using code:
+        #include <Rcpp.h>
+
+        // [[Rcpp::export]]
+        int fibonacci(const int x) {
+          if (x == 0) return(0);
+          if (x == 1) return(1);
+          return (fibonacci(x - 1)) + fibonacci(x - 2);
+        }'
+      )
Error in tools:::file_path_as_absolute(base:::system.file(..., package
= "Rcpp")) :
  file '' does not exist
srcCpp> ## Not run:
srcCpp> ##D
srcCpp> ##D sourceCpp("fibonacci.cpp")
srcCpp> ##D
srcCpp> ##D sourceCpp(code='
srcCpp> ##D   #include <Rcpp.h>
srcCpp> ##D
srcCpp> ##D   // [[Rcpp::export]]
srcCpp> ##D   int fibonacci(const int x) {
srcCpp> ##D     if (x == 0) return(0);
srcCpp> ##D     if (x == 1) return(1);
srcCpp> ##D     return (fibonacci(x - 1)) + fibonacci(x - 2);
srcCpp> ##D   }'
srcCpp> ##D )
srcCpp> ##D
srcCpp> ## End(Not run)
srcCpp>
srcCpp>
srcCpp>


--
Jiqiang
On Thu, Nov 15, 2012 at 1:34 PM, Dirk Eddelbuettel <edd at debian.org> wrote:
#
The error appears to be occurring in the call to RcppLdPath (made by both
sourceCpp and RStan). Here's the source code for that function:

RcppLdPath <- function() {
    if (nzchar(.Platform$r_arch)) { ## eg amd64, ia64, mips
        path <- Rcpp.system.file("lib",.Platform$r_arch)
    } else {
        path <- Rcpp.system.file("lib")
    }
    path
}

The call to Rcpp.system.file (looking for lib) is failing in your
configuration. I'm not sure why this would be.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20121115/0ad2abf1/attachment.html>
#
I see.  For some reason, my installing Rcpp from source last time did
not install the 64 bits lib, so
Rcpp.system.file("lib", .Platform$r_arch) for me returns "".

I reinstalled Rcpp 0.10.0 from source and made sure lib/x86_64 exists, then
everything is fine.

Thanks.

--
Jiqiang
On Thu, Nov 15, 2012 at 1:42 PM, JJ Allaire <jj.allaire at gmail.com> wrote:
#
On 15 November 2012 at 13:40, Jiqiang Guo wrote:
| Thanks.
| 
| The same error if I use cppFunction thought the example in sourceCpp
| use a string of c++ code passed using code:

Oh, sorry, my bad -- was short of time and couldn;t test, and don't even have
a mac.  I will let the mac squad get to it...

Dirk
 
| > require(Rcpp)
| >
| >      cppFunction(code='
| +        #include <Rcpp.h>
| +
| +        // [[Rcpp::export]]
| +        int fibonacci(const int x) {
| +          if (x == 0) return(0);
| +          if (x == 1) return(1);
| +          return (fibonacci(x - 1)) + fibonacci(x - 2);
| +        }'
| +      )
| Error in tools:::file_path_as_absolute(base:::system.file(..., package
| = "Rcpp")) :
|   file '' does not exist
| >
| >
| > ?cppFunction
| > example(sourceCpp)
| 
| srcCpp> ## Not run:
| srcCpp> ##D
| srcCpp> ##D sourceCpp("fibonacci.cpp")
| srcCpp> ##D
| srcCpp> ##D sourceCpp(code='
| srcCpp> ##D   #include <Rcpp.h>
| srcCpp> ##D
| srcCpp> ##D   // [[Rcpp::export]]
| srcCpp> ##D   int fibonacci(const int x) {
| srcCpp> ##D     if (x == 0) return(0);
| srcCpp> ##D     if (x == 1) return(1);
| srcCpp> ##D     return (fibonacci(x - 1)) + fibonacci(x - 2);
| srcCpp> ##D   }'
| srcCpp> ##D )
| srcCpp> ##D
| srcCpp> ## End(Not run)
| srcCpp>
| srcCpp>
| srcCpp>
| 
| 
| --
| Jiqiang
|
| On Thu, Nov 15, 2012 at 1:34 PM, Dirk Eddelbuettel <edd at debian.org> wrote:
| > On 15 November 2012 at 13:20, Jiqiang Guo wrote:
| > | I tried the example of sourceCpp on Mac mountain lion with R 2.15.1
| > | with the following error (I hit the similar error in using RStan as
| > | well).
| > |
| > | > library(Rcpp)
| > | > require(Rcpp)
| > | >
| > | >      sourceCpp(code='
| >
| > Operator error:  sourceCpp() takes a filename.  cppFunction() takes a
| > "program in a string" a la cxxfunction()
| >
| > Dirk
#
On 15 November 2012 at 13:42, JJ Allaire wrote:
| The error appears to be occurring in the call to RcppLdPath (made by both
| sourceCpp and RStan). Here's the source code for that function:
| 
| RcppLdPath <- function() {
| ? ? if (nzchar(.Platform$r_arch)) { ## eg amd64, ia64, mips
| ? ? ? ? path <- Rcpp.system.file("lib",.Platform$r_arch)
| ? ? } else {
| ? ? ? ? path <- Rcpp.system.file("lib")
| ? ? }
| ? ? path
| }
| 
| The call to Rcpp.system.file (looking for lib) is failing in your
| configuration. I'm not sure why this would be.

Possibly a non-standard Rcpp installation?

This has never before been an issue and we would have heard from Simon as
well as from legions of OS X users.  These R functions have been unchanged
for very large number of releases... and that particular snippet came

But if there is something programmatic we can / should do as a general
solution we'd be all ears.

Dirk
#
I think it is just I did something wrong with installing Rcpp from
source, which I cannot reproduce now.

Thanks very much.

--
Jiqiang
On Thu, Nov 15, 2012 at 1:55 PM, Dirk Eddelbuettel <edd at debian.org> wrote: