[Rcpp-commits] r195 - in pkg: R inst/examples/RcppInline

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Dec 18 01:59:27 CET 2009


Author: edd
Date: 2009-12-18 01:59:27 +0100 (Fri, 18 Dec 2009)
New Revision: 195

Modified:
   pkg/R/RcppInline.R
   pkg/inst/examples/RcppInline/RcppInlineWithLibsExamples.r
Log:
improved cfunction for inline

Modified: pkg/R/RcppInline.R
===================================================================
--- pkg/R/RcppInline.R	2009-12-17 03:54:09 UTC (rev 194)
+++ pkg/R/RcppInline.R	2009-12-18 00:59:27 UTC (rev 195)
@@ -15,7 +15,7 @@
 cfunction <- function(sig=character(), body=character(), includes=character(), otherdefs=character(),
                       language=c("C++", "C", "Fortran", "F95", "ObjectiveC", "ObjectiveC++"),
                       verbose=FALSE, convention=c(".Call", ".C", ".Fortran"), Rcpp=FALSE,
-                      compileargs=character(), linkargs=character()) {
+                      cppargs=character(), cxxargs=character(), libargs=character()) {
 
   convention <- match.arg(convention)
 
@@ -37,23 +37,24 @@
 
   if (Rcpp) {
       includes <- paste(includes, "\n#include <Rcpp.h>\n", sep="")
-      cxxflags <- paste("PKG_CXXFLAGS=\"",
-                        Rcpp:::RcppCxxFlags(), 		# information from Rcpp
-                        paste(compileargs,collapse=" "),# headers from users if any
-                        "\"", collapse=" ", sep=" ")
-      ldflags <-  paste("PKG_LIBS=\"",
-                        Rcpp:::RcppLdFlags(),
-                        paste(linkargs, collapse=" "), # libraries from users if any
-                        "\"", collapse=" ", sep=" ")
-  } else {
-      cxxflags <- paste("PKG_CXXFLAGS=\"",
-                        paste(compileargs,collapse=" "),# headers from users if any
-                        "\"", sep="")
-      ldflags <-  paste("PKG_LIBS=\"",
-                        paste(linkargs, collapse=" "), # libraries from users if any
-                        "\"", sep="")
+      cxxargs <- c(Rcpp:::RcppCxxFlags(), cxxargs)	# prepend information from Rcpp
+      libargs <- c(Rcpp:::RcppLdFlags(), libargs)	# prepend information from Rcpp
   }
-  pkgargs <-  paste(c(cxxflags, ldflags, ""), collapse=" ")
+  if (length(cppargs) != 0) {
+      args <- paste(cppargs, collapse=" ")
+      if (verbose) cat("Setting PKG_CPPFLAGS to", args, "\n")
+      Sys.setenv(PKG_CPPFLAGS=args)
+  }
+  if (length(cxxargs) != 0) {
+      args <- paste(cxxargs, collapse=" ")
+      if (verbose) cat("Setting PKG_CXXFLAGS to", args, "\n")
+      Sys.setenv(PKG_CXXFLAGS=args)
+  }
+  if (length(libargs) != 0) {
+      args <- paste(libargs, collapse=" ")
+      if (verbose) cat("Setting PKG_LIBS to", args, "\n")
+      Sys.setenv(PKG_LIBS=args)
+  }
 
   ## GENERATE THE CODE
   for ( i in seq_along(sig) ) {
@@ -149,7 +150,7 @@
   } ## for along signatures
 
   ## WRITE AND COMPILE THE CODE
-  libLFile <- compileCode(f, code, language, verbose, pkgargs)
+  libLFile <- compileCode(f, code, language, verbose)
 
   ## SET A FINALIZER TO PERFORM CLEANUP
   cleanup <- function(env) {
@@ -171,7 +172,7 @@
     ## important here: all variables are kept in the local environment
     fn <- function(arg) {
    	  if ( !file.exists(libLFile) )
-   	    libLFile <<- compileCode(f, code, language, verbose, pkgargs)
+   	    libLFile <<- compileCode(f, code, language, verbose)
    	  if ( !( f %in% names(getLoadedDLLs()) ) ) dyn.load(libLFile)
     }
 
@@ -217,7 +218,7 @@
 }
 
 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-compileCode <- function(f, code, language, verbose, pkgargs="") {
+compileCode <- function(f, code, language, verbose) {
   ## Prepare temp file names
   if ( .Platform$OS.type == "windows" ) {
     ## windows files
@@ -243,11 +244,8 @@
   if ( file.exists(libLFile) ) file.remove( libLFile )
   if ( file.exists(libLFile2) ) file.remove( libLFile2 )
 
-  cmd <- paste(pkgargs, R.home(component="bin"), "/R CMD SHLIB ", libCFile, sep="")
-  if (verbose) {
-      cat("Compilation argument:\n")
-      cat(" ", cmd)
-  }
+  cmd <- paste(R.home(component="bin"), "/R CMD SHLIB ", libCFile, sep="")
+  if (verbose) cat("Compilation argument:\n", cmd, "\n")
   compiled <- system(cmd, intern=!verbose)
 
   if ( !file.exists(libLFile) && file.exists(libLFile2) ) libLFile <- libLFile2

Modified: pkg/inst/examples/RcppInline/RcppInlineWithLibsExamples.r
===================================================================
--- pkg/inst/examples/RcppInline/RcppInlineWithLibsExamples.r	2009-12-17 03:54:09 UTC (rev 194)
+++ pkg/inst/examples/RcppInline/RcppInlineWithLibsExamples.r	2009-12-18 00:59:27 UTC (rev 195)
@@ -23,8 +23,8 @@
     funx <- cfunction(signature(ignored="numeric"), gslrng,
                       includes="#include <gsl/gsl_rng.h>",
                       Rcpp=FALSE,
-                      compileargs="-I/usr/include",
-                      linkargs="-lgsl -lgslcblas")
+                      cppargs="-I/usr/include",
+                      libargs="-lgsl -lgslcblas")
 
     cat("Calling first example\n")
     funx(0)
@@ -66,16 +66,16 @@
     funx <- cfunction(signature(par="numeric"), gslrng,
                       includes="#include <gsl/gsl_rng.h>",
                       Rcpp=TRUE,
-                      compileargs="-I/usr/include",
-                      linkargs="-lgsl -lgslcblas")
+                      cppargs="-I/usr/include",
+                      libargs="-lgsl -lgslcblas")
     cat("\n\nCalling second example without -DBeSilent set\n")
     print(funx(0)["value"])
 
     funx <- cfunction(signature(par="numeric"), gslrng,
                       includes="#include <gsl/gsl_rng.h>",
                       Rcpp=TRUE,
-                      compileargs="-I/usr/include -DBeSilent",
-                      linkargs="-lgsl -lgslcblas")
+                      cppargs="-I/usr/include -DBeSilent",
+                      libargs="-lgsl -lgslcblas")
     cat("\n\nCalling second example with -DBeSilent set\n")
     print(funx(1)["value"])
 
@@ -118,7 +118,7 @@
                       includes="#include <gsl/gsl_rng.h>",
                       Rcpp=TRUE,
                       compileargs="-I/usr/include",
-                      linkargs="-lgsl -lgslcblas")
+                      libargs="-lgsl -lgslcblas")
     cat("\n\nCalling second example without -DBeSilent set\n")
     print(funx(0)["value"])
 
@@ -126,7 +126,7 @@
                       includes="#include <gsl/gsl_rng.h>",
                       Rcpp=TRUE,
                       compileargs="-I/usr/include -DBeSilent",
-                      linkargs="-lgsl -lgslcblas")
+                      libargs="-lgsl -lgslcblas")
     cat("\n\nCalling second example with -DBeSilent set\n")
     print(funx(1)["value"])
 



More information about the Rcpp-commits mailing list