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

Hadley Wickham hadley at rice.edu
Thu Oct 13 17:11:37 CEST 2011


> 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()

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/


More information about the Rcpp-devel mailing list