Building R package with DLLs - r

I am attempting to create a binary package that contains precompiled .dll files which the package relies on to function. I have the file tkogl2.dll which needs to be loaded upon usage of the package. After creating the package and attempting to build using devtools::build(binary = TRUE) I receive the following error:
Error: package or namespace load failed for 'GUImorphTest' in library.dynam(lib, package, package.lib):
DLL 'tkogl2.dll' not found: maybe not installed for this architecture?
错误: 载入失败
停止执行
*** arch - x64
Error: package or namespace load failed for 'GUImorphTest' in library.dynam(lib, package, package.lib):
DLL 'tkogl2.dll' not found: maybe not installed for this architecture?
错误: 载入失败
停止执行
ERROR: loading failed for 'i386', 'x64'
This is most likely due to the NAMESPACE file, though I am a novice in this process, so I am not entirely sure what it should consist. It currently only contains useDynLib(tkogl2.dll) which I found to put there from googling. It could also be where I put the .dll in my package. I simply created a libs folder as seen here:
Any help is appreciated, thank you!
edit:
Here is onload fct
.onLoad <- function(libname, pkgname) {
chname <- "tkogl2"
file.ext <- .Platform$dynlib.ext #dll file
dlname <- paste(chname, file.ext, sep = "")
if (is.character(.Platform$r_arch) && .Platform$r_arch != "")
path <- file.path("libs", .Platform$r_arc, dlname)
else path <- file.path("libs", dlname)
file <- system.file(path, package = pkgname, lib.loc = libname)[1] #grabs full file name
print(file)
tryCatch(tcl("load", file, "Tkogl2"),
error = function(e)
warning("loading tkogl2 failed", call. = FALSE))
}

Related

R Studio aborts after loading libraries, base R throws error

I have not used R on my Mac in a few weeks, and now I am experiencing an issue where RStudio aborts my session immediately when trying to load any packages. When trying to load packages using base R, I get this error:
> library(dplyr)
Error: package or namespace load failed for ‘dplyr’ in dyn.load(file, DLLpath = DLLpath, ...):
unable to load shared object '/Users/User/Rlibs/vctrs/libs/vctrs.so':
dlopen(/Users/User/Rlibs/vctrs/libs/vctrs.so, 0x0006): Library not loaded: '/Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libR.dylib'
Referenced from: '/Users/User/Rlibs/vctrs/libs/vctrs.so'
Reason: tried: '/Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libR.dylib' (no such file), '/usr/local/lib/libR.dylib' (no such file), '/usr/lib/libR.dylib' (no such file)
It seems like R is not looking in the correct location to find my libraries. I have checked the location using:
.libPaths()
which reports back two directories. One user-specific path [1] "/Users/User/Rlibs" and one system-wide path [2] "/Library/Frameworks/R.framework/Versions/4.2/Resources/library". The user-specific path contains all of the packages I have previously installed, while the system-wide path contains only a small subset of R packages.
I have already tried reinstalling both RStudio and R.
How can I fix this to prevent RStudio from aborting my session?
Per #Roland, update.packages(ask = FALSE, checkBuilt = TRUE) worked.

Error: package or namespace load failed for ‘tidyverse’: object ‘relocate’ is not exported by 'namespace:dplyr'

I installed tidyverse using this command:
install.packages("tidyverse")
But after installing when I call the library with:
library(tidyverse)
I get this error:
Error: package or namespace load failed for ‘tidyverse’: object ‘relocate’ is not exported by 'namespace:dplyr'
I am trying to do this simple thing:
a = 1:100
tibble(a, b = 2 * a)
But that gives me this error message:
Error in tibble(a, b = 2 * a) : could not find function "tibble"
I tried to install again using:
install.packages("devtools")
devtools::install_github("hadley/tidyverse")
This is too slow. It never finished installing.
Am I missing something in installing process? Please help.
I had a similar problem: when calling library(bibliometrix), it threw a similar error (just not the same package, and not the same object that was "not exported" by dplyr).
I updated all packages with update.packages(ask = FALSE), as suggested by #user2554330. After that, it still wasn't working, so I restarted Rstudio, and that solved the problem, apparently.

Trouble adding package to library() after installing package

I keep getting the same error, for both first for XLConnect, (which I thought was a java problem) and now rJava (which is also not working). This is the error message I get when I 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
'/Users/snyderk2/Library/R/3.4/library/rJava/libs/rJava.so':
dlopen(/Users/snyderk2/Library/R/3.4/library/rJava/libs/rJava.so, 6):
Library not loaded: #rpath/libjvm.dylib Referenced from:
/Users/snyderk2/Library/R/3.4/library/rJava/libs/rJava.so Reason:
image not found
I am new to R, and just need to figure out how to get these packages working, thanks!
Try (check your java version and change accordingly):
Sys.setenv(JAVA_HOME = "C:/Program Files/Java/jre-9.0.1")
And then load library.
Install package xlsx if you are trying to access Excel file by entering install.packages("xlsx", dependencies = T) in your console.
Another R package for working with excel data which does not require rJava is openxlsx. I've found it works faster than java-based packages, which is a nice bonus.

R: object ‘set_global_graph_attrs’ is not exported from 'namespace:DiagrammeR'

I wanted to install Mxnet library and found on this forum the topic where was described how do it .
cran <- getOption("repos")
cran["dmlc"] <- "https://apache-mxnet.s3-accelerate.dualstack.amazonaws.com/R/CRAN/"
options(repos = cran)
install.packages("mxnet")
library("mxnet")
and then i got the error
Error: package or namespace load failed for ‘mxnet’:
object ‘set_global_graph_attrs’ is not exported from 'namespace:DiagrammeR'
what's wrong?
DiagrammeR library is installed.
There is some weird thing goes with mxnet installation on windows. I also experienced that problem a few days ago. What helped me is to install diagrammeR 0.9 manually:
# Make sure you have devtools installed already
require(devtools)
install_version("DiagrammeR", version = "0.9.0", repos = "http://cran.us.r-project.org")
require(DiagrammeR)
And after doing that, try to install mxnet - now it should work.
Let me know if it helps.
I had exactly the same problem with loading mxnet. Your suggestion of installing DiagrammeR manually seems to have fixed it. Unfortunately, it simply exposed another error.
Error: package or namespace load failed for ‘mxnet’:
.onLoad failed in loadNamespace() for 'mxnet', details:
call: inDL(x, as.logical(local), as.logical(now), ...)
error: unable to load shared object 'C:/Users/steve/Documents/R/win-library/3.4/mxnet/libs/x64/libmxnet.dll':
LoadLibrary failure: The specified module could not be found.
I think the "onLoad" function must be missing. The dll referenced above, libmxnet.dll, is exactly where it should be.

Error with loading my package in r?

I built my own package and everythings goes well. then when I generate src file for .c files I got the problem.
1- I used devtools::use_rcpp()
2- Then create a file to put these lines: #' #useDynLib Mypackage
#' #importFrom Rcpp sourceCpp
NULL
Then when I build adn load the package I got this error:
Error: package or namespace load failed for ‘Mypackage’ in library.dynam(lib, package, package.lib):
shared object ‘Mypackage.so’ not found
Error: loading failed
Execution halted
ERROR: loading failed
Note that: my namespace files generated automatically by roxygen2.
any help please?
I built my package again using the Rcpp.package.skeleton() :
I then built my own funciton in R where I call the .C file but I got this error.
My_func <- function(x){
x*4
.Call(rcpp_hello_world,PACKAGE = "Mypackage")[[1]]
}
> My_func(4)
Error in .Call(rcpp_hello_world, PACKAGE = "MixRVinE") :
first argument must be a string (of length 1) or native symbol reference

Resources