libstableR doesn't build for macOS - r

I would like to use the R package libstableR on a mac. I'm not a contributor/author of the package and have contacted them regarding libstableR failing for osx:
After contacting the authors who said the problem is probably related to R not knowing where GSL is on the computer, I applied two minor edits to
the DESCRIPTION and the src/Makevars in addition to requiring the mac user to do the following:
be sure to have homebrew
be sure to have gsl
be sure to have Rcpp and RcppGSL: just install.packages("RcppGSL") in R
Sources:
Dirk Eddelbuettel answer on SO
GREGGJ website on homebrew installing GSL on macs
Applying the steps above has changed the output of
devtools::install_github("swihart/libstableR")
From:
<SNIP>
** testing if installed package can be loaded
Error: package or namespace load failed for ‘libstableR’ in dyn.load(file, DLLpath = DLLpath, ...):
unable to load shared object '/Users/swihartbj/RLIB/libstableR/libs/libstableR.so':
dlopen(/Users/swihartbj/RLIB/libstableR/libs/libstableR.so, 6): Symbol not found: _stable_set_THREADS
Referenced from: /Users/swihartbj/RLIB/libstableR/libs/libstableR.so
Expected in: flat namespace
in /Users/swihartbj/RLIB/libstableR/libs/libstableR.so
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/Users/swihartbj/RLIB/libstableR’
to:
** testing if installed package can be loaded
Error: package or namespace load failed for ‘libstableR’ in dyn.load(file, DLLpath = DLLpath, ...):
unable to load shared object '/Users/swihartbj/RLIB/libstableR/libs/libstableR.so':
dlopen(/Users/swihartbj/RLIB/libstableR/libs/libstableR.so, 6): Symbol not found: _libstableR_stable_cdf
Referenced from: /Users/swihartbj/RLIB/libstableR/libs/libstableR.so
Expected in: flat namespace
in /Users/swihartbj/RLIB/libstableR/libs/libstableR.so
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/Users/swihartbj/RLIB/libstableR’
Where basically instead of complaining about _stable_set_THREADS the errors pertain to _libstableR_stable_cdf. libstableR_stable_cdf is an exported function. The leading underscore in _libstableR_stable_cdf is put there when Roxygen/Rcpp is applied.
I have tinkered and online searched for about two months trying to get this up and running, and now come to SO for help.
Anyway to get libstableR working on a mac?

So, I went to https://cran.rstudio.com/web/packages/libstableR/index.html and grabbed https://cran.rstudio.com/src/contrib/libstableR_1.0.tar.gz (I knew Bruce had a repo but I wanted to see the original).
I had gsl (homebrew) and the RcppGSL installed already.
I did a quick devtools::document() since I figured it used Rcpp everywhere and got:
Error in dyn.load(dllfile) :
unable to load shared object '/private/tmp/libstableR/src/libstableR.so':
dlopen(/private/tmp/libstableR/src/libstableR.so, 6): Symbol not found: _libstableR_stable_cdf
Referenced from: /private/tmp/libstableR/src/libstableR.so
Expected in: flat namespace
in /private/tmp/libstableR/src/libstableR.so
There were two definitions (one Rcpp exposed and one internal) for stable_cdf() so I made the internal one int_stable_cdf() and made the change to the singular call to it.
I still got a similar error so I suspected they hand-crafted some things.
I went in and made the NAMESPACE auto-generate from roxygen comments and added //' #exports for the key exposed functions.
I removed init.c since Rcpp auto-gen's registration code now.
I still got an error, but this time for stable_set_THREADS being unavailable.
It turns out they really don't care abt macOS folks at all:
#ifdef __WIN32
void stable_set_THREADS(unsigned int value) {
/*
SYSTEM_INFO sysinfo;
GetSystemInfo(&sysinfo);
THREADS = (unsigned int)sysinfo.dwNumberOfProcessors;
*/
THREADS = 12;
}
#else
#ifdef __unix
void stable_set_THREADS(unsigned int value) {
if (value == 0) THREADS = sysconf(_SC_NPROCESSORS_ONLN);
else THREADS = value;
//printf("\nCPUs = %u\n",THREADS);
}
#endif
#endif
I removed the unix ifdef, tweaked a few more incidentals and it works.
I'll see if we can get this on GH and get the maintainers to OK some further tweaks to make it easier for others to contribute.

Related

"object not found" during package build/install

I'm at a loss to debug building/installing a package. Building a package "MyProjekt" through
> devtools::build("MyProjekt")
works fine, even though
> devtools::document()
Updating MyProjekt documentation
Loading MyProjekt
Error: object 'rank' not found whilst loading namespace 'MyProjekt'
fails.
Attempting to install the built (pure R) package
> install.packages(pkgs="./MyProjekt.tar.gz")
...
Error: package or namespace load failed for 'MyProjekt':
object 'rank' not found whilst loading namespace 'MyProjekt'
Error: loading failed
Execution halted
...
ERROR: loading failed for 'i386', 'x64'
also fails.
Unfortunately the term 'rank' is a common term in my domain and I have hundreds of hits when searching in my files for that term.
How might I start a systematic way to hunt this bug down?
The toolchain mistakenly generates S3method(...) in the NAMESPACE file.
Follow this answer and edit the NAMESPACE file by hand. Replace occurrences of S3method(f) with export(f).
I'm not certain this is repeatable. The generated files appear to be not just written, but also read during a subsequent package build (by devtools? by roxygen2?). Add your comments if this works/does not work for you.

NLoptr failed to install on Mac: unable to load shared object

I'm trying to install the package nloptr on Mac OS High Sierra in order to use many nice packages like lme4, and I'm using RStudio inside Anaconda, with R 3.4.2. I have also installed NLopt (downloaded from the NLopt website, not the development version. I have also installed Xcode command line tool. But I still can't install nloptr, and get this
Error: package or namespace load failed for ‘nloptr’ in dyn.load(file, DLLpath = DLLpath, ...):
unable to load shared object '/Users/lambda/anaconda3/lib/R/library/nloptr/libs/nloptr.so':
dlopen(/Users/lambda/anaconda3/lib/R/library/nloptr/libs/nloptr.so, 6): Symbol not found: _nlopt_add_equality_mconstraint
Referenced from: /Users/lambda/anaconda3/lib/R/library/nloptr/libs/nloptr.so
Expected in: flat namespace
in /Users/lambda/anaconda3/lib/R/library/nloptr/libs/nloptr.so
I already searched online for what to do, and did add the path where NLopt was installed to LD_LIBRARY_PATH in the /etc/ldpaths file, but I still get the same error. Yes, I have the same problem as in Trouble installing nloptr package on R 3.3.0, but I didn't find a solution that works there since the person who asked that question resolved it himself and I don't know what he meant when he said "installed as a root". Can anyone help?
Also, I got something like this when installing NLopt with CMake, and this happened to many different functions:
In file included from f77api.c:103:
./f77funcs.h:57:14: warning: 'nlopt_minimize_constrained' is deprecated
[-Wdeprecated-declarations]
*info = nlopt_minimize_constrained((nlopt_algorithm) *algorithm,
^
./nlopt.h:348:35: note: 'nlopt_minimize_constrained' has been explicitly marked
deprecated here
int maxeval, double maxtime) NLOPT_DEPRECATED;
^
./nlopt.h:320:43: note: expanded from macro 'NLOPT_DEPRECATED'
# define NLOPT_DEPRECATED __attribute__((deprecated))
^
Would this be why the library isn't loaded?
BTW, I have installed Rcpp and updated it. Rcpp works on my computer.
Update: I changed the default C and C++ compiler to clang4 downloaded from R project. I tried the installation again, and got a different error:
Error: package or namespace load failed for ‘nloptr’ in dyn.load(file, DLLpath = DLLpath, ...):
unable to load shared object '/Users/lambda/anaconda3/lib/R/library/nloptr/libs/nloptr.so':
dlopen(/Users/lambda/anaconda3/lib/R/library/nloptr/libs/nloptr.so, 6): Library not loaded: #rpath/libnlopt.0.dylib
Referenced from: /Users/lambda/anaconda3/lib/R/library/nloptr/libs/nloptr.so
Reason: image not found
Error: loading failed
I have tried to tell R where the library is by Sys.geteng(DYLD_LIBRARY_PATH = "/usr/local/lib"), but it didn't work. It actually appears that R does know where the shared library is, according to the messages I got from installation, but it just can't load it. Please help!
Never mind, I reinstalled Anaconda, and installed the standalone R and RStudio (not within Anaconda), and those packages all installed successfully. Maybe it's a bad idea to use the RStudio inside Anaconda.
Edit: For those who run into similar scenarios: I switched to Microsoft R Open (MRO), since I'm dealing a lot with linear algebra recently. Then when I tried to install nloptr in MRO, I got a similar error message that shared library failed to load because image not found. I reinstalled the CRAN R 3.4.3 and nloptr installed totally fine there. So I found where nloptr was installed in CRAN R 3.4.3 by .libPaths(), copied the nloptr folder to where MRO stores packages, and used the utility RSwitch to change the default version of R to MRO. Then I loaded nloptr in MRO, installed packages that depend on it, and used those packages; they worked fine. I don't know what's wrong with MRO that caused the error, but at least this worked.

rJava doesn't load in R 3.4.2 and MacOS Sierra 10.12.6

Here's the error I get:
> library(rJava)
Error: package or namespace load failed for ‘rJava’:
.onLoad failed in loadNamespace() for 'rJava', details:
call: dyn.load(file, DLLpath = DLLpath, ...)
error: unable to load shared object '/Library/Frameworks/R.framework/Versions/3.4/Resources/library/rJava/libs/rJava.so':
dlopen(/Library/Frameworks/R.framework/Versions/3.4/Resources/library/rJava/libs/rJava.so, 6): Library not loaded: #rpath/libjvm.dylib
Referenced from: /Library/Frameworks/R.framework/Versions/3.4/Resources/library/rJava/libs/rJava.so
Reason: image not found
I see this is by no means a unique problem.. I've tried the solutions here, here and here. No success.
Some more details: I'm using R GUI, but I also can't load rJava through R terminal. I also didn't have any issue with rJava on R 3.3.s
You have two options here:
get older release of R and use precompiled version of rJava
get rJava sources and compile it for yourself
Note that rJava (most recent sources) require some features that are not embedded inside XCode and clang that is available via AppStore. You will need to do some low level stuff when it comes to building rJava package.
You can find detailed instruction here: http://www.owsiak.org/r-3-4-rjava-macos-and-even-more-mess/
If you decide to use older release of R, it's still a struggle to get it working, but way less to do: http://www.owsiak.org/r-java-rjava-and-macos-adventures/
JAVA_HOME path is different for different version of MAC OS.
In some cases there is /jre folder and in some cases it is not after /Home director manually go towards /server folder with CD command in terminal and using pwd copy the entire path use that to set the java.home then you can easily load rJava library. This is how I was able to fix the issue
options("java.home"="/Library/Java/JavaVirtualMachines/jdk-9.0.1.jdk/Contents/Home/lib")
Sys.setenv(LD_LIBRARY_PATH='$JAVA_HOME/server')
dyn.load('/Library/Java/JavaVirtualMachines/jdk-9.0.1.jdk/Contents/Home/lib/server/libjvm.dylib')
library(rJava)

How can I activate rJava on macOS?

> library('rJava')
Error: package or namespace load failed for ‘rJava’:
.onLoad failed in loadNamespace() for 'rJava', details:
call: dyn.load(file, DLLpath = DLLpath, ...)
error: unable to load shared object '/Library/Frameworks/R.framework/Versions/3.4/Resources/library/rJava/libs/rJava.so':
dlopen(/Library/Frameworks/R.framework/Versions/3.4/Resources/library/rJava/libs/rJava.so, 6): Library not loaded: #rpath/libjvm.dylib
Referenced from: /Library/Frameworks/R.framework/Versions/3.4/Resources/library/rJava/libs/rJava.so
Reason: image not found
I installed JDK9 version on my Macbook Pro
My OS is 10.12.6 Sierra
I tried to activate rJava many times.
I searched Google a lot.. but I could not solve that problem..
There are numerous issues you may find here.
incorrect rJava package
issues with JVM configuration
problems related to package sources (you need most recent release of clang to compile most recent version of rJava)
there are issues with R and it's configuration utility for JVM configuration.
In general, there is no easy solution you can apply for each and every environment. Take a look here:
http://www.owsiak.org/r-3-4-rjava-macos-and-even-more-mess/
I have collected sources of most of the issues you can find while working with JVM and R. Also, pay attention to JDK 9 - it no longer comes with JRE. In past, JRE was internal part of JDK.
In general, I don't think you can solve this issue without, at least, little bit of work.
For all the helping people with comments: "This link may provide ...". Just take a look at the content and you will know why I don't copy-paste it here ;)

Installing & using the asbio package under OS X

I'm a TA in a statistics class, and the students are supposed to use the "asbio" package in r for multiple comparisons. Some of those who have OSX are complaining that asbio will not load. I cannot reproduce the error on my own mac.
Here are the errors one of the students is seeing:
>library(asbio)
Loading required package: tcltk
Error : .onLoad failed in loadNamespace() for 'tcltk', details:
call: dyn.load(file, DLLpath = DLLpath, ...)
error: unable to load shared object '/Library/Frameworks/R.framework/Versions/3.1/Resources/library/tcltk/libs/tcltk.so':
dlopen(/Library/Frameworks/R.framework/Versions/3.1/Resources/library/tcltk/libs/tcltk.so, 10): Library not loaded: /opt/X11/lib/libX11.6.dylib
Referenced from: /Library/Frameworks/R.framework/Versions/3.1/Resources/library/tcltk/libs/tcltk.so
Reason: image not found
Error: package ‘tcltk’ could not be loaded
> install.packages("tcltk")
Warning in install.packages :
package ‘tcltk’ is not available (for R version 3.1.1)
Here are a few things students have tried:
install tcltk2: "It works now, but I still get errors" (Sorry, I know that's a confusing answer, but it's what I have)
install xquartz: "Now it works."
I suspect that xquartz is the right answer here, but if anybody could explain what's going on and confirm, that would be awesome.
(And why the ^& would a numerical statistics package need tcl/tk anyway???)
tcl/tk needs an X11 environment to work in for graphical output and Apple no longer ships an X11 environment with their operating system. XQuartz fills that gap, but is a separate install. Said install makes the X11 libraries available (look at the missing libraries in your errors) and those libraries—in turn—make graphical operations with tcl/tk possible.
the absio package has functions that let you do animation (like anim.ci) which rely on the graphics capabilities of tcl/tk.
A student in the class posted the following instructions:
1) Install xquartz. You don't need to click it ever again after installing it.
2) Restart computer.
3) Open Rstudio (or whatever R). Run library(tcltk). Don't use require or install.packages for it. Computer should now open up xquartz on its own.
4) Run install.packages("asbio")
5) library(asbio)
6) You should be able to run pairw.anova.
(I'm still waiting to see if the student wants credit by name here, but in any case, I'm thankful to them.)

Resources