Permalink
Browse files

Better use of .C in has_devel

  • Loading branch information...
hadley committed Sep 13, 2012
1 parent 5ad43b0 commit 056fa666b0f07197733323d8986115e0d7f6ed72
Showing with 6 additions and 6 deletions.
  1. +6 −6 R/has-devel.r
View
@@ -1,6 +1,6 @@
#' 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
#' returns an error.
@@ -9,17 +9,17 @@
#' has_devel()
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)
+
+ dll <- dyn.load(dylib)
on.exit(dyn.unload(dylib), add = TRUE)
- stopifnot(do.call(".C", list("foo",0L))[[1]] == 1L)
+ stopifnot(.C(dll$foo, 0L)[[1]] == 1L)
TRUE
}

0 comments on commit 056fa66

Please sign in to comment.