[Rcpp-commits] r4063 - in pkg/Rcpp: . R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Mon Dec 3 23:11:11 CET 2012
Author: jjallaire
Date: 2012-12-03 23:11:11 +0100 (Mon, 03 Dec 2012)
New Revision: 4063
Modified:
pkg/Rcpp/ChangeLog
pkg/Rcpp/R/Attributes.R
Log:
function to check whether R development tools are currently installed
Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog 2012-12-03 14:30:56 UTC (rev 4062)
+++ pkg/Rcpp/ChangeLog 2012-12-03 22:11:11 UTC (rev 4063)
@@ -1,3 +1,8 @@
+2012-12-03 JJ Allaire <jj at rstudio.org>
+
+ * R/Attributes.R: added function to check whether R development
+ tools are currently installed
+
2012-12-03 Romain Francois <romain at r-enthusiasts.com>
* src/Module.cpp: move BEGIN_RCPP/END_RCPP to Module__invoke
Modified: pkg/Rcpp/R/Attributes.R
===================================================================
--- pkg/Rcpp/R/Attributes.R 2012-12-03 14:30:56 UTC (rev 4062)
+++ pkg/Rcpp/R/Attributes.R 2012-12-03 22:11:11 UTC (rev 4063)
@@ -618,3 +618,32 @@
gsub("\\s", "", linkingTo)
}
+# check if R development tools are installed (cache successful result)
+.hasDevelTools <- FALSE
+.checkDevelTools <- function() {
+ if (!.hasDevelTools) {
+ # create temp source file
+ tempFile <- file.path(tempdir(), "foo.c")
+ cat("void foo() {}\n", file = tempFile)
+ on.exit(unlink(tempFile))
+
+ # set working directory to tempdir (revert on exit)
+ oldDir <- setwd(tempdir())
+ on.exit(setwd(oldDir), add = TRUE)
+
+ # attempt the compilation and note whether we succeed
+ cmd <- paste(R.home(component="bin"), .Platform$file.sep, "R ",
+ "CMD SHLIB foo.c", sep = "")
+ result <- suppressWarnings(system(cmd, intern = TRUE))
+ assignInMyNamespace(".hasDevelTools", is.null(attr(result, "status")))
+
+ # if we build successfully then remove the shared library
+ if (.hasDevelTools) {
+ lib <- file.path(tempdir(),
+ paste("foo", .Platform$dynlib.ext, sep=''))
+ unlink(lib)
+ }
+ }
+ .hasDevelTools
+}
+
More information about the Rcpp-commits
mailing list