Error with loading my package in r? - 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

Related

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.

R package caret fails to load

I am using R4.0.0, I used the 'caret' package successfully a week ago. But now when I am trying to rerun my program, I get the following error:
Error: package or namespace load failed for ‘caret’ in get(Info[i, 1], envir = env):
cannot open file 'C:/Users/Documents/R/win-library/4.0/iterators/R/iterators.rdb': No such file or directory
How can I fix this problem?

Building R package with DLLs

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))
}

"no such symbol C_contour" error when loading package "foreign" in R

I want to use the package foreign to turn an Octave text file representing a read audio file into R vector data; however, when I try to load the package using library(foreign), I get the following error message:
Loading required package: Matrix
Error: package or namespace load failed for ‘Matrix’ in FUN(X[[i]], ...):
no such symbol C_contour in package /Library/Frameworks/R.framework/Versions/3.4/Resources/library/graphics/libs/graphics.so
Error: package ‘Matrix’ could not be loaded
I tried deleting the R.framework file and reinstalling (a method which worked for someone else with a similar error) and continued to encounter this error.
Does anyone know what the holdup here is?

Can not load R package when exporting methods which is not s4 generic "as.vector"

I am trying to load package "Matrix" and get this error:
Error : Function found when exporting methods from the namespace ‘Matrix’ which is not S4 generic: ‘as.vector’
In addition: Warning message:
package ‘Matrix’ was built under R version 3.3.0
Error: package or namespace load failed for ‘Matrix’
I have tried restarting and installing etc.
One thing I have tried is this (R Cannot allocate memory though memory seems to be available)
wd <- getwd()
assign('.First', function(x) {
require('Matrix') #and whatever other packages you're using
file.remove(".RData") #already been loaded
rm(".Last", pos=.GlobalEnv) #otherwise won't be able to quit R without it restarting
setwd(wd)
}, pos=.GlobalEnv)
assign(".Last", function() {
system("R --no-site-file --no-init-file --quiet")
}, pos=.GlobalEnv)
save.image() #or only save the things you want to be reloaded.
q("no")
But I cant seem to get that solution working to try and see if it will load under "Vanilla" R
Edit: I was able to try and load the package under "Vanilla" R but I still get the same error

Resources