[Rcpp-devel] Request for help with compiling Rcpp example

Dirk Eddelbuettel edd at debian.org
Thu Oct 13 18:44:20 CEST 2011


On 13 October 2011 at 10:11, Hadley Wickham wrote:
| > My best guess is that you have not installed the Rtools correctly.  Can you
| > compile a simple 'hello, world' example in C or C++?  Can you rebuild R
| > packages from source?
| 
| I wrote an function to check that you have a valid R development
| environment (with help from Simon Urbanek) for devtools.  See code
| below - and check with has_devel()

Nice. We should borrow that idea as the issue comes up /a lot/.

One improvement I would make--even though each user has his own tempdir()--is
to follow inline and also make the filename temporary ... in which case you
can dispense with the different on.exit(unlink(...)) calls.  I think. Untest :)

Dirk


| Hadley
| 
| 
| has_devel <- function() {
|   foo_path <- file.path(tempdir(), "foo.c")
| 
|   cat("void foo(int *bar) { *bar=1; }\n", file = foo_path)
|   on.exit(unlink(foo_path))
| 
|   R("CMD SHLIB foo.c", tempdir())
|   dylib <- file.path(tempdir(), paste("foo", .Platform$dynlib.ext, sep=''))
|   on.exit(unlink(dylib), add = TRUE)
| 
|   dyn.load(dylib)
|   on.exit(dyn.unload(dylib), add = TRUE)
| 
|   stopifnot(do.call(".C", list("foo",0L))[[1]] == 1L)
|   TRUE
| }
| 
| R <- function(options, path = tempdir()) {
|   r_path <- shQuote(file.path(R.home("bin"), "R"))
|   in_dir(path, system_check(paste(r_path, options)))
| }
| 
| system_check <- function(cmd) {
|   res <- system(cmd)
|   if (res != 0) {
|     stop("Command failed (", res, ")", call. = FALSE)
|   }
|   invisible(TRUE)
| }
| 
| in_dir <- function(dir, code) {
|   cur <- getwd()
|   setwd(dir)
|   on.exit(setwd(cur))
| 
|   force(code)
| }
| 
| -- 
| Assistant Professor / Dobelman Family Junior Chair
| Department of Statistics / Rice University
| http://had.co.nz/

-- 
"Outside of a dog, a book is a man's best friend. Inside of a dog, it is too
dark to read." -- Groucho Marx


More information about the Rcpp-devel mailing list