<div class="gmail_quote"><div class="im">| Hi, Dirk,<br>
|<br>
</div><div class="im">| Sorry to disturb you again.<br>
|<br>
| Actually, I am also very interested in how to call back the R commands in<br>
| 'cxxfunction'. Do you have some examples or tutorial about this? <br>
<br>
</div>Please keep questions on the mailing list.<br>
<div><div></div><div class="h5"><br>
Dirk<br>
<br>
|<br>
| Thank you very much.<br>
|<br>
| Best regards,<br>
|<br>
| Kent<br>
|<br>
|<br>
| On Fri, Oct 14, 2011 at 4:39 PM, Dirk Eddelbuettel <<a href="mailto:edd@debian.org">edd@debian.org</a>> wrote:<br>
|<br>
|<br>
| Hi Kent,<br>
|<br>
| On 14 October 2011 at 16:00, Jian Kang wrote:<br>
| | Hi, Dirk,<br>
| |<br>
| | Sorry for delay. <br>
| |<br>
| | I tried to install the R and Rtools again, and run the program again,<br>
| then it<br>
| | works. <br>
|<br>
| Excellent!<br>
|<br>
| | But here is some warnings, I am not sure whether this is OK in the<br>
| future.<br>
| |<br>
| | Compilation argument:<br>
| | C:/R/Rsoft/bin/i386/R CMD SHLIB file7e446574.cpp 2><br>
| | file7e446574.cpp.err.txt <br>
| | g++ -I"C:/R/Rsoft/include" -I"C:/R/Rsoft/library/Rcpp/include" <br>
| -O2<br>
| | -Wall -c file7e446574.cpp -o file7e446574.o<br>
| | g++ -shared -s -static-libgcc -o file7e446574.dll tmp.def file7e446574.o<br>
| C:/R/<br>
| | Rsoft/library/Rcpp/lib/i386/libRcpp.a -LC:/R/Rsoft/bin/i386 -lR<br>
| | cygwin warning:<br>
| | MS-DOS style path detected: C:/R/Rsoft/etc/i386/Makeconf<br>
| | Preferred POSIX equivalent is: /cygdrive/c/R/Rsoft/etc/i386/Makeconf<br>
| | CYGWIN environment variable option "nodosfilewarning" turns off this<br>
| | warning.<br>
| | Consult the user's guide for more details about POSIX paths:<br>
| | <a href="http://cygwin.com/cygwin-ug-net/using.html#using-pathnames" target="_blank">http://cygwin.com/cygwin-ug-net/using.html#using-pathnames</a><br>
|<br>
| That started with more recent Cygwin / MinGW versions. Google for this, I<br>
| think there were tricks to turn it off. This came up on r-help once or<br>
| twice<br>
| too.<br>
|<br>
| But to reiterate: it is just a warning, and it has nothing to do with Rcpp.<br>
|<br>
| Dirk<br>
|<br>
|<br>
| | Thank you very much.<br>
| |<br>
| | Best,<br>
| |<br>
| | Kent<br>
| |<br>
| |<br>
| | On Thu, Oct 13, 2011 at 6:46 PM, Dirk Eddelbuettel <<a href="mailto:edd@debian.org">edd@debian.org</a>><br>
| wrote:<br>
| |<br>
| |<br>
| | On 13 October 2011 at 18:15, Jian Kang wrote:<br>
| | | Thanks for your reply.<br>
| | |<br>
| | | Here is the response of 'Hello World' program:<br>
| | |<br>
| | | > src='#include <iostream><br>
| | | + using namespace std;<br>
| | | + void main()<br>
| | | + {<br>
| | | + cout << "Hello World!" << endl;<br>
| | | + cout << "Welcome to C++ Programming" << endl;<br>
| | | + }'<br>
| | | > <br>
| | | > fx <- cxxfunction(src,plugin = "Rcpp",verbose=T)<br>
| |<br>
| | PBKAC -- wrong call of cxxfunction(). You can see below how the<br>
| generated<br>
| | code does *not* include your actual function.<br>
| |<br>
| | The correct idiom is<br>
| |<br>
| | fx <- cxxfunction(signature(), body=src,plugin =<br>
| "Rcpp",verbose=TRUE)<br>
| |<br>
| | Dirk<br>
| |<br>
| |<br>
| | | >> setting environment variables: <br>
| | | PKG_LIBS = C:/R/Rsoft/library/Rcpp/lib/i386/libRcpp.a<br>
| | |<br>
| | | >> LinkingTo : Rcpp<br>
| | | CLINK_CPPFLAGS = -I"C:/R/Rsoft/library/Rcpp/include" <br>
| | |<br>
| | | >> Program source :<br>
| | |<br>
| | | 1 : <br>
| | | 2 : // includes from the plugin<br>
| | | 3 : <br>
| | | 4 : #include <Rcpp.h><br>
| | | 5 : <br>
| | | 6 : <br>
| | | 7 : #ifndef BEGIN_RCPP<br>
| | | 8 : #define BEGIN_RCPP<br>
| | | 9 : #endif<br>
| | | 10 : <br>
| | | 11 : #ifndef END_RCPP<br>
| | | 12 : #define END_RCPP<br>
| | | 13 : #endif<br>
| | | 14 : <br>
| | | 15 : using namespace Rcpp;<br>
| | | 16 : <br>
| | | 17 : <br>
| | | 18 : // user includes<br>
| | | 19 : <br>
| | | 20 : <br>
| | | 21 : // declarations<br>
| | | 22 : extern "C" {<br>
| | | 23 : SEXP file3a1c304e( ) ;<br>
| | | 24 : }<br>
| | | 25 : <br>
| | | 26 : // definition<br>
| | | 27 : <br>
| | | 28 : SEXP file3a1c304e( ){<br>
| | | 29 : BEGIN_RCPP<br>
| | | 30 : <br>
| | | 31 : END_RCPP<br>
| | | 32 : }<br>
| | | 33 : <br>
| | | 34 : <br>
| | | Compilation argument:<br>
| | | C:/R/Rsoft/bin/i386/R CMD SHLIB file3a1c304e.cpp 2><br>
| | | file3a1c304e.cpp.err.txt <br>
| | | g++ -I"C:/R/Rsoft/include" -I"C:/R/Rsoft/library/Rcpp/<br>
| include" <br>
| | -O2<br>
| | | -Wall -c file3a1c304e.cpp -o file3a1c304e.o<br>
| | | g++ -shared -s -static-libgcc -o file3a1c304e.dll tmp.def<br>
| file3a1c304e.o<br>
| | C:/R/<br>
| | | Rsoft/library/Rcpp/lib/i386/libRcpp.a -LC:/R/Rsoft/bin/i386 -lR<br>
| | | cygwin warning:<br>
| | | MS-DOS style path detected: C:/R/Rsoft/etc/i386/Makeconf<br>
| | | Preferred POSIX equivalent is: /cygdrive/c/R/Rsoft/etc/i386/<br>
| Makeconf<br>
| | | CYGWIN environment variable option "nodosfilewarning" turns<br>
| off this<br>
| | | warning.<br>
| | | Consult the user's guide for more details about POSIX paths:<br>
| | | <a href="http://cygwin.com/cygwin-ug-net/using.html#using-pathnames" target="_blank">http://cygwin.com/cygwin-ug-net/using.html#using-pathnames</a><br>
| | | Error in as.function.default(c(value, if (is.null(bd) || is.list<br>
| (bd))<br>
| | list(bd)<br>
| | | else bd), : <br>
| | | invalid formal argument list for "function"<br>
| | |<br>
| | | Here, I also tried the test by Hadley,<br>
| | |<br>
| | | _devel()<br>
| | | cygwin warning:<br>
| | | MS-DOS style path detected: C:/R/Rsoft/etc/i386/Makeconf<br>
| | | Preferred POSIX equivalent is: /cygdrive/c/R/Rsoft/etc/i386/<br>
| Makeconf<br>
| | | CYGWIN environment variable option "nodosfilewarning" turns<br>
| off this<br>
| | | warning.<br>
| | | Consult the user's guide for more details about POSIX paths:<br>
| | | <a href="http://cygwin.com/cygwin-ug-net/using.html#using-pathnames" target="_blank">http://cygwin.com/cygwin-ug-net/using.html#using-pathnames</a><br>
| | | gcc -I"C:/R/Rsoft/include" -I"C:/R/Rsoft/library/Rcpp/<br>
| include" <br>
| | -O3<br>
| | | -Wall -std=gnu99 -c foo.c -o foo.o<br>
| | | gcc -shared -s -static-libgcc -o foo.dll tmp.def foo.o C:/R/Rsoft<br>
| /library<br>
| | /Rcpp/<br>
| | | lib/i386/libRcpp.a -LC:/R/Rsoft/bin/i386 -lR<br>
| | | [1] TRUE<br>
| | |<br>
| | | Sorry that I don't really get it how to rebuild R packages from<br>
| source.<br>
| | |<br>
| | | Thanks,<br>
| | |<br>
| | | Kent<br>
| | |<br>
| | | On Thu, Oct 13, 2011 at 5:11 PM, Hadley Wickham <<a href="mailto:hadley@rice.edu">hadley@rice.edu</a>><br>
| wrote:<br>
| | |<br>
| | | > My best guess is that you have not installed the Rtools<br>
| | correctly. Can<br>
| | | you<br>
| | | > compile a simple 'hello, world' example in C or C++?<br>
| Can you<br>
| | rebuild R<br>
| | | > packages from source?<br>
| | |<br>
| | | I wrote an function to check that you have a valid R<br>
| development<br>
| | | environment (with help from Simon Urbanek) for devtools.<br>
| See code<br>
| | | below - and check with has_devel()<br>
| | |<br>
| | | Hadley<br>
| | |<br>
| | |<br>
| | | has_devel <- function() {<br>
| | | foo_path <- file.path(tempdir(), "foo.c")<br>
| | |<br>
| | | cat("void foo(int *bar) { *bar=1; }\n", file = foo_path)<br>
| | | on.exit(unlink(foo_path))<br>
| | |<br>
| | | R("CMD SHLIB foo.c", tempdir())<br>
| | | dylib <- file.path(tempdir(), paste("foo",<br>
| .Platform$dynlib.ext,<br>
| | sep=''))<br>
| | | on.exit(unlink(dylib), add = TRUE)<br>
| | |<br>
| | | dyn.load(dylib)<br>
| | | on.exit(dyn.unload(dylib), add = TRUE)<br>
| | |<br>
| | | stopifnot(do.call(".C", list("foo",0L))[[1]] == 1L)<br>
| | | TRUE<br>
| | | }<br>
| | |<br>
| | | R <- function(options, path = tempdir()) {<br>
| | | r_path <- shQuote(file.path(R.home("bin"), "R"))<br>
| | | in_dir(path, system_check(paste(r_path, options)))<br>
| | | }<br>
| | |<br>
| | | system_check <- function(cmd) {<br>
| | | res <- system(cmd)<br>
| | | if (res != 0) {<br>
| | | stop("Command failed (", res, ")", call. = FALSE)<br>
| | | }<br>
| | | invisible(TRUE)<br>
| | | }<br>
| | |<br>
| | | in_dir <- function(dir, code) {<br>
| | | cur <- getwd()<br>
| | | setwd(dir)<br>
| | | on.exit(setwd(cur))<br>
| | |<br>
| | | force(code)<br>
| | | }<br>
| | |<br>
| | | --<br>
| | | Assistant Professor / Dobelman Family Junior Chair<br>
| | | Department of Statistics / Rice University<br>
| | | <a href="http://had.co.nz/" target="_blank">http://had.co.nz/</a><br>
| | | _______________________________________________<br>
| | | Rcpp-devel mailing list<br>
| | | <a href="mailto:Rcpp-devel@lists.r-forge.r-project.org">Rcpp-devel@lists.r-forge.r-project.org</a><br>
| | | <a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/</a><br>
| listinfo/<br>
| | rcpp-devel<br>
| | |<br>
| | |<br>
| |<br>
| | --<br>
| | "Outside of a dog, a book is a man's best friend. Inside of a dog,<br>
| it is<br>
| | too<br>
| | dark to read." -- Groucho Marx<br>
| |<br>
| |<br>
|<br>
| --<br>
| "Outside of a dog, a book is a man's best friend. Inside of a dog, it is<br>
| too<br>
| dark to read." -- Groucho Marx<br>
|<br>
|<br>
<br>
--<br>
"Outside of a dog, a book is a man's best friend. Inside of a dog, it is too<br>
dark to read." -- Groucho Marx<br>
</div></div></div><br>