g++ version; un-/re-installing R packages

11 views
Skip to first unread message

Bob Carpenter

unread,
Mar 1, 2012, 7:21:45 PM3/1/12
to stan...@googlegroups.com
Question 1
----------
Does anyone know how to control the version of
g++ used by R? The default version shipped with the
Mac isn't up to our template defaults yet, but it's
easy to install a new compiler that is. I'd like to
tell R to use that one.

Otherwise, I think we're going to have to bite the
bullet and duplicate every function in our probability
lib to deal with defaults (this is, by the way, what
Boost does -- the core problem is that without the c++0x
extensions, you can't have a template parameter default
for a function.

Question 2
----------
How do I work with R when developing packages so
that I can uninstall and reinstall a package without
quitting R?

I managed to get Rcpp modules linking to the Stan
code, but I can't figure out how to get R to forget
about the last version and load the new one.

I can create my Rcpp module-based package using their
template as follows

SHELL
$ R CMD build mypkg
$ R CMD check mypkg
$ R CMD install mypkg

R
> require("mypkg")
> foo(2,3)

That all works fine, with foo(2,3) being
defined in my package. But then I change some code
and rebuild and reinstall the package

SHELL
$ R CMD remove mypkg
$ R CMD build mypkg
$ R CMD check mypkg
$ R CMD install mypkg

And then I go into R and do this:

R
> detach("package:mypkg")
> require("mypkg")

and I get the old version. If I then quit out of R
and start again, I get the new one without going back
to the shell, etc.

There's so much noise on the R lists about installing
packages that I can't find a single useful bit of advice.

- Bob


Jack Tanner

unread,
Mar 1, 2012, 8:43:05 PM3/1/12
to stan...@googlegroups.com
On Thursday, March 01, 2012 7:21:45 PM, Bob Carpenter wrote:

> How do I work with R when developing packages so
> that I can uninstall and reinstall a package without
> quitting R?

Does it work if you do

detach(package:mypkg, unload=TRUE)

Bob Carpenter

unread,
Mar 1, 2012, 10:00:01 PM3/1/12
to stan...@googlegroups.com
I tried to use "unload=TRUE" with detach, but it
crashes R with a segfault. My guess from the message is
that it's using memory mapping for its cache.

If I don't unload, it brings back the previous version.

I can't find any help online -- lots of people have seen
these bugs, but no answers to what's going on I could find.

I'm hoping I'm just detaching/library-ing wrong somehow.

- Bob


> detach(package:mypkg, unload=TRUE)
> require('mypkg')
Loading required package: mypkg

*** caught segfault ***
address 0x90, cause 'memory not mapped'

Traceback:
1: .Call(symbol)
2: Module(m, pkg, mustStart = TRUE)
3: doTryCatch(return(expr), name, parentenv, handler)
4: tryCatchOne(expr, names, parentenv, handlers[[1L]])
5: tryCatchList(expr, classes, parentenv, handlers)
6: tryCatch({ mod <- Module(m, pkg, mustStart = TRUE) if
(isTRUE(direct)) { populate(mod, ns) } else {
forceAssignInNamespace(m, mod, ns) }}, error = function(e) {
stop(sprintf("failed to load module %s from package %s\n%s", m,
pkg, conditionMessage(e)))})
7: loadRcppModules()
8: fun(...)
9: doTryCatch(return(expr), name, parentenv, handler)
10: tryCatchOne(expr, names, parentenv, handlers[[1L]])
11: tryCatchList(expr, classes, parentenv, handlers)
12: tryCatch(fun(...), error = identity)
13: runHook(".onLoad", package, env, package.lib, package)
14: loadNamespace(package, c(which.lib.loc, lib.loc), keep.source =
keep.source)
15: doTryCatch(return(expr), name, parentenv, handler)
16: tryCatchOne(expr, names, parentenv, handlers[[1L]])
17: tryCatchList(expr, classes, parentenv, handlers)
18: tryCatch(expr, error = function(e) { call <- conditionCall(e)
if (!is.null(call)) { if (identical(call[[1L]],
quote(doTryCatch))) call <- sys.call(-4L) dcall <-
deparse(call)[1L] prefix <- paste("Error in", dcall, ": ")
LONG <- 75L msg <- conditionMessage(e) sm <-
strsplit(msg, "\n")[[1L]] w <- 14L + nchar(dcall, type = "w") +
nchar(sm[1L], type = "w") if (is.na(w)) w <- 14L +
nchar(dcall, type = "b") + nchar(sm[1L], type = "b")
if (w > LONG) prefix <- paste(prefix, "\n ", sep = "")
} else prefix <- "Error : " msg <- paste(prefix,
conditionMessage(e), "\n", sep = "")
.Internal(seterrmessage(msg[1L])) if (!silent &&
identical(getOption("show.error.messages"), TRUE)) {
cat(msg, file = stderr()) .Internal(printDeferredWarnings()) }
invisible(structure(msg, class = "try-error"))})
19: try({ ns <- loadNamespace(package, c(which.lib.loc, lib.loc),
keep.source = keep.source) dataPath <- file.path(which.lib.loc,
package, "data") env <- attachNamespace(ns, pos = pos, dataPath =
dataPath, deps)})
20: library(package, lib.loc = lib.loc, character.only = TRUE,
logical.return = TRUE, warn.conflicts = warn.conflicts, quietly =
quietly, keep.source = keep.source)
21: doTryCatch(return(expr), name, parentenv, handler)
22: tryCatchOne(expr, names, parentenv, handlers[[1L]])
23: tryCatchList(expr, classes, parentenv, handlers)
24: tryCatch(library(package, lib.loc = lib.loc, character.only = TRUE,
logical.return = TRUE, warn.conflicts = warn.conflicts, quietly =
quietly, keep.source = keep.source), error = function(e) e)
25: require("mypkg")

Possible actions:
1: abort (with core dump, if enabled)
2: normal R exit
3: exit R without saving workspace
4: exit R saving workspace
Selection:

That was fun. The result was a seg-fault:

Ben Goodrich

unread,
Mar 2, 2012, 12:54:18 AM3/2/12
to stan...@googlegroups.com
On Thursday, March 1, 2012 7:21:45 PM UTC-5, Bob Carpenter wrote:
Question 1
----------
Does anyone know how to control the version of
g++ used by R?  The default version shipped with the
Mac isn't up to our template defaults yet, but it's
easy to install a new compiler that is.  I'd like to
tell R to use that one.

I think the easiest thing would be to make the new version of g++ the system default.

Otherwise, see

http://cran.r-project.org/doc/manuals/R-admin.html#Customizing-package-compilation
 

Question 2
----------
How do I work with R when developing packages so
that I can uninstall and reinstall a package without
quitting R?

I have never seen loading, unloading, and reloading a package work well, except if the R code is very simple and there is no compiled code.

If you just need to test modified R code, you can usually just paste it into the R session. But if you modify source code, it is easiest to quit R, reinstall the package, and restart R.

Ben

Austin F. Frank

unread,
Mar 2, 2012, 1:15:00 AM3/2/12
to stan...@googlegroups.com
The load_all() function from Hadley Wickham's devtools package may
help here. Also check out the dev_mode() function for building
development version of packages outside of the system directory.

https://github.com/hadley/devtools

HTH,
/au

--
Austin Frank
GPG Public Key (D7398C2F): http://aufrank.net/personal.asc

Ben Goodrich

unread,
Mar 2, 2012, 1:19:53 AM3/2/12
to stan...@googlegroups.com
On Thursday, March 1, 2012 7:21:45 PM UTC-5, Bob Carpenter wrote:
Question 1
----------
Does anyone know how to control the version of
g++ used by R?  The default version shipped with the
Mac isn't up to our template defaults yet, but it's
easy to install a new compiler that is.  I'd like to
tell R to use that one.

Perhaps more worrisome is the fact that CRAN currently uses GCC 4.2.1 to build binary packages. See

http://cran.r-project.org/web/checks/check_flavors.html#r-release-macosx-ix86

So, if 4.2.1 is not good enough, then there won't be Mac binary for the *stan package. At that point, users would have to install the package from source and they would have to have a proper toolchain.

Looks to me like fallback is unavoidable for the time being.

 

Otherwise, I think we're going to have to bite the
bullet and duplicate every function in our probability
lib to deal with defaults (this is, by the way, what
Boost does -- the core problem is that without the c++0x
extensions, you can't have a template parameter default
for a function.

You might be able to get away with a macro that takes template arguments and expands itself into functions. Eigen does this occasionally.

Ben

Reply all
Reply to author
Forward
0 new messages