error with R CMD check because of package dependency - r

Background
I am creating a newpackage that depends on oldpackage, and have indicated this dependency in the file newpackage/DESCRIPTION.
Furthermore,
oldpackage is installed in the directory, ~/lib/R
my .Rprofile includes .libPaths("~/lib/R")
hence, I can successfully load oldpackage without specifying the library location, e.g., using the command library(oldpackage) in R
Despite the ability to load the package without having its library specified, R CMD check newpackage gives an error indicating that it can not fine oldpackage:
checking whether the package can be loaded ... ERROR
Loading required package: oldpackage
Error: package 'oldpackage' could not be loaded
In addition: Warning message:
In library(pkg, character.only = TRUE, logical.return = TRUE, lib.loc = lib.loc) :
there is no package called 'oldpackage'
Execution halted
It looks like this package has a loading problem: see the messages for
details.
Questions:
Why is R unable to find the package?
Can I specify the library location in the DESCRIPTION file?

Regarding question 1), it is both a FAQ and yet somewhat annoying. R CMD check runs in vanilla mode, so it will not find user-level libraries. As I recall, setting R_LIBS="...." in the call helps, so try that.
Regarding question 2), no you cannot give a location in DESCRIPTION. Which makes sense as that file needs to work 'everywhere' whereas your location info is local to your machine.

Related

Bioconductor update keeps failing to update after a half hour

I'm working with R and need to install some packages.
> BiocManager::install( c( list, of, packages) )
Error: Bioconductor version '3.13' requires R version '4.1'; use
`BiocManager::install(version = '3.16')` with R version 4.2; see
https://bioconductor.org/install
ok, so I need to update bioconductor. No problem:
BiocManager::install(version = '3.16')
At this point I get an absolute torrent of text output to my terminal for over half an hour. It ends with this:
** testing if installed package can be loaded from temporary location
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (ggpubr)
The downloaded source packages are in
‘/tmp/Rtmpu3HGq9/downloaded_packages’
Error in .install_github(todo, lib = lib, lib.loc = lib.loc, repos = repos, :
argument "update" is missing, with no default
In addition: Warning message:
package(s) not installed when version(s) same as or greater than current; use
`force = TRUE` to re-install: 'BiocVersion'
So I do it again with the "force" option, but the process insists on starting all over again from scratch, so I have to wait another half-hour and get the same problem. I've done this almost a dozen times now with variations on the command and environment settings and this is eating up days of work time.
I also noticed another message in the output:
Warning: unable to access index for repository https://bioconductor.org/packages/3.16/bioc/src/contrib:
cannot open URL 'https://bioconductor.org/packages/3.16/bioc/src/contrib/PACKAGES'
Am I being blocked by some internal network? I've also tried setting a proxy with Sys.setenv(http_proxy="[proxyAddress]:[port]")
To no avail.
I'm Running out of ideas and would much appreciate any help.
This issue is discussed here: https://github.com/Bioconductor/BiocManager/issues/142. Basically it will be fixed in the next release of BiocManager, which is whatever comes after 1.30.19.

Issue with loading Tidyverse in RStudio

How to do i resolve the following code error?
library(tidyverse)
Error: package or namespace load failed for ‘tidyverse’:
.onLoad failed in loadNamespace() for 'tidyselect', details:
call: is_string(x)
error: object 'rlang_is_string' not found
In addition: Warning message:
package ‘tidyverse’ was built under R version 3.5.3
For persistent errors of type, first, ensure you are working with the latest version of R. The installr package is a very convenient way to do this.
Then, start new R session (ideally, not in RStudio).
Uninstall tidyverse, tidyselect, and rlang
# if you are using multiple libraries, you may need to specify libpath,
# using the following: lib="~/R/win-library/3.6"
# you can check using the .libPaths() command
remove.packages("rlang")
remove.packages("tidyselect")
remove.packages("tidyverse")
and, reinstall them one by one with dependencies = TRUE
install.packages("rlang", dependencies = TRUE)
install.packages("tidyselect", dependencies = TRUE)
install.packages("tidyverse", dependencies = TRUE)
That should do it.
I also encounter a similar problem like you, which I'm unable to load the tidyverse too.
Hope this discuss from the tidyverse github issues maybe relevant to you.
https://github.com/tidyverse/googledrive/issues/275
Here's one of our typical explanations of this. Note that this is not specific to googledrive or rlang. It's an R + Windows gotcha. I suspect for you is rlang (at least).
Please note that on Windows, it is very important to quit or restart
all R processes before upgrading , because if any R process has
loaded, it will keep the .dll file open and the installer will not be
able to overwrite .dll. The error message when this happens is very
easy to overlook, and the new version will be partially installed: the
package description and R code will be updated but the compiled code
(in .dll) will not.

tcltk dependency when trying to use ordPens library in Anaconda R

I've been wrestling with this for days, and while there seem to be a number of tcltk problems in StackOverflow, I can't find the key to unlock this. Hope someone can help.
I'm using Anaconda and Jupyter notebooks to access R. I'm running this on Windows 10. It works wonderfully most of the time. I'm trying to use the ordPens package, but when I call the library, I get an error. The error seems to be that it requires the tcltk package to be loaded, to use the ordPens package.
library(ordPens, verbose=TRUE)
Warning message in find.package(package, lib.loc, quiet = TRUE, verbose = verbose):
"package 'ordPens' found more than once,
using the one found in 'C:/Program Files/R/R-3.3.0/library/ordPens'"Warning message:
"package 'ordPens' was built under R version 3.3.2"Loading required package: tcltk
Error: package 'tcltk' could not be loaded
Traceback:
library(ordPens, verbose = TRUE)
.getRequiredPackages2(pkgInfo, quietly = quietly)
stop(gettextf("package %s could not be loaded", sQuote(pkg)),
. call. = FALSE, domain = NA)
But tcltk can't be installed directly, as a normal package. Apparently this causes problems in non-WIndows environments, when it isn't always loaded at initial build. But tcltk does appear to be available.
capabilities("tcltk")
tcltk: TRUE
I tried a workaround by installing ordPens into the directory used by my R console, rather than Anaconda, and then pointing Anaconda at that (drawing on this post, which has helped in the past) :
.libPaths('C:/Program Files/R/R-3.3.0/library')
but it still didn't work.
Any ideas? As a last resort, I could just save my outputs from the Jupyter/Anaconda environment, process them with ordPens in the R console, and then save back. But I'd love to know how to fix this - and really to understand what is going on.

Installing EBImage on Windows 7

I'm very new to R. I've tried to install the package EBImage
> source("http://bioconductor.org/biocLite.R")
> biocLite("EBImage")
and got the Warning:
installed directory not writable, cannot update packages 'foreign',
'lattice', 'Matrix', 'mgcv', 'nlme'
As I've tried to load an image
> f = system.file("images", "C:/aeskuimg/Patterns/Homogenious/h.jpg", package="EBImage")
> hom = readImage(f)
I've got the error:
Error in readImage(f) : Unable to determine type: Empty filename.
I suspect this is because of the prior warning.
Is there any solution there?
The warning can be ignored, it indicates that some packages were installed in a way that does not allow them to be updated, probably by an Administrator account whereas you're running as a regular user. To use an R package, load it first
library(EBImage)
Probably just
readImage("C:/aeskuimg/Patterns/Homogenious/h.jpg")
will work (R has tab completion, so no need to try too hard at typing the correct path; also file.choose() provides graphical navigation).
system.file() is used to specify a path relative to the location in which a package has been installed, and is typically used to reference an example file the package authors have distributed with the package. Probably after your command the value of f is character(0), which is R's way of saying that that the path you specified, relative to the installed location of the EBImage package, does not exist; system.file() has an argument mustWork=TRUE that will generate an error if the file path is incorrect.

How force R to load package, `library()` fails due to dependency?

How force R to load package when some (not crucial) packages it depends on aren't installed ?
Motivation : sometimes I have to use R in places, where I can't automatically install required packages. Doing so manually is very time consuming and in most cases I need only a vary small part of functions contained in installed package.
Typical message error in this case is :
> library(packageX)
Loading required package: packageY
Error: package ‘packageY’ could not be loaded
In addition: Warning messages:
In library(pkg, character.only = TRUE, logical.return = TRUE, lib.loc = lib.loc) : there is no package called ‘packageY’
Mayby 'devtools' package will be helpful. But I haven't investigate it.
If you cannot install the dependencies, I think your only option is to remove those packages from the Depends field of DESCRIPTION file of packageX and try to rebuild packageX
You can look at the source of the package to figure out which functions you need and what dependencies they need. You may want to collaborate with the author/maintainer of the package on this part. You could create a private version of the package that does not have the dependencies and the other functionality that you don't need.
If this is only for your personal use and the license for the package allows it (gpl and similar) then you don't need the authors permission to extract those pieces you want. If you want to link your package to this for distribution then you should work with the original author. I know a couple of package authors wanted just a couple of functions from one of my packages and I agreed that loading my entire package (and dependencies) was overkill for what they wanted to do, so I worked with them and they have copies of the functions in their package without needing to depend on mine. When I update one of the functions I send a copy to them to update their copy as well.

Resources