Skip to content

Commit

Permalink
Better use of .C in has_devel
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley committed Sep 13, 2012
1 parent 5ad43b0 commit 056fa66
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions R/has-devel.r
@@ -1,6 +1,6 @@
#' Check if you have a development environment installed. #' Check if you have a development environment installed.
#' #'
#' Thanks to the suggestion of Simon Urbanek. #' Thanks to the suggestion of Simon Urbanek.
#' #'
#' @return TRUE if your development environment is correctly set up, otherwise #' @return TRUE if your development environment is correctly set up, otherwise
#' returns an error. #' returns an error.
Expand All @@ -9,17 +9,17 @@
#' has_devel() #' has_devel()
has_devel <- function() { has_devel <- function() {
foo_path <- file.path(tempdir(), "foo.c") foo_path <- file.path(tempdir(), "foo.c")

cat("void foo(int *bar) { *bar=1; }\n", file = foo_path) cat("void foo(int *bar) { *bar=1; }\n", file = foo_path)
on.exit(unlink(foo_path)) on.exit(unlink(foo_path))

R("CMD SHLIB foo.c", tempdir()) R("CMD SHLIB foo.c", tempdir())
dylib <- file.path(tempdir(), paste("foo", .Platform$dynlib.ext, sep='')) dylib <- file.path(tempdir(), paste("foo", .Platform$dynlib.ext, sep=''))
on.exit(unlink(dylib), add = TRUE) on.exit(unlink(dylib), add = TRUE)

dyn.load(dylib) dll <- dyn.load(dylib)
on.exit(dyn.unload(dylib), add = TRUE) on.exit(dyn.unload(dylib), add = TRUE)


stopifnot(do.call(".C", list("foo",0L))[[1]] == 1L) stopifnot(.C(dll$foo, 0L)[[1]] == 1L)
TRUE TRUE
} }

0 comments on commit 056fa66

Please sign in to comment.