Install R package from GitHub in package vignette - r

I've built an R package and it's available on CRAN. I am updating one of the vignettes and I would like to install a package from GitHub in the vignette. The R CMD Checks ran smoothly on my machine, but after submission to CRAN I received a message indicating that I need to install the package to a temporary library.
I used this code to attempt to install the package to a temporary directory. The code works on my local machine and the R CMD Checks pass locally (devtools::check() and devtools::check(remote = TRUE)). But the checks fail when run on the CRAN machine (rhub::check_for_cran()).
# adding temp_path to .libPaths
temp_path <- file.path(tempdir(), "gt_folder"); dir.create(temp_path)
lib_path <-.libPaths()
.libPaths(c(lib_path, temp_path))
remotes::install_github("rstudio/gt", lib = temp_path)
gt::gt(mtcars)
This is the error I see from rhub::check_for_cran(). It seems the dependencies are not being handled correctly.
ERROR: dependencies 'lazyeval', 'reshape2', 'scales', 'tibble' are not available for package 'ggplot2'
- removing 'C:/Users/USERVzKWFkopnQ/AppData/Local/Temp/RtmpIjoZQH/working_dir/RtmpiwGvJu/gt_folder/ggplot2'
ERROR: dependencies 'fansi', 'utf8', 'vctrs' are not available for package 'pillar'
- removing 'C:/Users/USERVzKWFkopnQ/AppData/Local/Temp/RtmpIjoZQH/working_dir/RtmpiwGvJu/gt_folder/pillar'
The downloaded source packages are in
'C:\Users\USERVzKWFkopnQ\AppData\Local\Temp\RtmpIjoZQH\working_dir\RtmpiwGvJu\downloaded_packages'
ERROR: dependencies 'checkmate', 'commonmark', 'dplyr', 'fs', 'ggplot2', 'sass', 'scales', 'tibble', 'tidyselect' are not available for package 'gt'
- removing 'C:/Users/USERVzKWFkopnQ/AppData/Local/Temp/RtmpIjoZQH/working_dir/RtmpiwGvJu/gt_folder/gt'
Quitting from lines 18-45 (install_from_github.Rmd)
Error: processing vignette 'install_from_github.Rmd' failed with diagnostics:
there is no package called 'gt'
--- failed re-building 'install_from_github.Rmd'
SUMMARY: processing the following file failed:
'install_from_github.Rmd'
Error: Vignette re-building failed.
Execution halted
Here's a light-weight package with only one function and a vignette illustrating the problem https://github.com/ddsjoberg/pkginstallgh
Here is the note I received from CRAN
Dear maintainer,
Pls see
<https://cran.r-project.org/web/checks/check_results_gtsummary.html>.
The check problems on the Debian systems are caused by attempts to write
to the user library to which all packages get installed before checking
(and which now is remounted read-only for checking).
Having package code which is run as part of the checks and attempts to
write to the user library violates the CRAN Policy's
Packages should not write in the user’s home filespace (including
clipboards), nor anywhere else on the file system apart from the R
session’s temporary directory (or during installation in the location
pointed to by TMPDIR: and such usage should be cleaned up).
In your case, you need to teach remotes::install_github("rstudio/gt") to
install to a temporary library and use it from there.

Related

Installing R package ERROR: installing binary package failed

Complete newbie here, so there is probably something glaringly bad here. I created a Project following Hadley Wickham's book on R packages, and now I am trying add it to github for remote install (repository for reference).
Running devtools::install_github("alutterb/abcmlr") generated the following output:
Downloading GitHub repo alutterb/abcmlr#master
√ checking for file 'C:\Users\amlut\AppData\Local\Temp\RtmpMpn5uJ\remotes7146c405dd7\alutterb-abcmlr-918bf05/DESCRIPTION' ...
- preparing 'abcmlr':
√ checking DESCRIPTION meta-information ...
- checking for LF line-endings in source and make files and shell scripts
- checking for empty or unneeded directories
- building 'abcmlr_0.1.0.tar.gz'
Installing package into ‘C:/Users/amlut/Documents/R/win-library/3.5’
(as ‘lib’ is unspecified)
* installing *binary* package 'abcmlr' ...
cp: unknown option -- )
Try '/Rtools/bin/cp --help' for more information.
ERROR: installing binary package failed
* removing 'C:/Users/amlut/Documents/R/win-library/3.5/abcmlr'
In R CMD INSTALL
Error in i.p(...) :
(converted from warning) installation of package ‘C:/Users/amlut/AppData/Local/Temp/RtmpMpn5uJ/file71463953e7b/abcmlr_0.1.0.tar.gz’ had non-zero exit status
In my repository, I have a Linux executable that is to be used with wsl as well as an .exe file that is called in my R code. These may be the culprits, but I am not entirely sure. The error states that it failed to install the binary package, but install_github() takes a source package, so I am not sure what is going on. Any help is appreciated.
Thank you.
EDIT: This problem is solved. It was because of a line in my DESCRIPTION file that had to do with Built.
Check your %PATH% and type: where cp.
Another cp (like one from the Git for Windows distribution) might overshadow the RTools cp, which might explain the error message.
As commented by the OP hkj447, the error was trigger by a line in the DESCRIPTION file:
Built: R 3.5.3; ; 2019-06-14 21:17:43 UTC; windows
As seen in this thread:
You have a field called 'Built:' in your package's DESCRIPTION file;
R normally tries to inject that field itself when it builds your package from sources.
I deleted "Built"'s line in DESCRIPTION and then installed again.
This time, no error appeared.

Error: package or namespace load failed, object ... not found

I am running a new install of R (3.5.0) and RStudio (1.1.414). [Note I have now updated to 3.5.1 and 1.1.453 and am still experiencing the issues below with the exception of the "built under R version 3.5.1" warning messages]
I have installed the rlang package using install.packages("rlang") without encountering any issues but when I attempt to load the package I get the following error
Error: package or namespace load failed for ‘rlang’:
.onLoad failed in loadNamespace() for 'rlang', details:
call: dots_list(...)
error: object 'rlang_dots_list' not found
In addition: Warning message:
package ‘rlang’ was built under R version 3.5.1
I've uninstalled and reinstalled rlang (closing restarting RStudio in between each command) and am still encountering this error.
I am also encountering a set of similar (although possible totally unrelated) issue with other packages
RStudio provides the following warning every startup
[Workspace loaded from ~/.RData]
Error in yaml.load(readLines(con), error.label = error.label, ...) :
object 'C_unserialize_from_yaml' not found
Error in yaml.load(readLines(con), error.label = error.label, ...) :
object 'C_unserialize_from_yaml' not found
library(devtools) gives the following errors
Error: package or namespace load failed for ‘devtools’ in FUN(X[[i]], ...):
no such symbol digest in package //[redacted]/My
Documents/R/win-library/3.5/digest/libs/x64/digest.dll
In addition: Warning message:
package ‘devtools’ was built under R version 3.5.1
Someone on twitter asked for the results of packageDescription("rlang")
I've copied the output below in case it helps with troubleshooting.
Package: rlang
Version: 0.2.1
Title: Functions for Base Types and Core R and 'Tidyverse' Features
Description: A toolbox for working with base types, core R features like the condition system, and core
'Tidyverse' features like tidy evaluation.
Authors#R: c( person("Lionel", "Henry", ,"lionel#rstudio.com", c("aut", "cre")), person("Hadley", "Wickham",
,"hadley#rstudio.com", "aut"), person("RStudio", role = "cph") )
License: GPL-3
LazyData: true
ByteCompile: true
Depends: R (>= 3.1.0)
Suggests: crayon, knitr, methods, pillar, rmarkdown (>= 0.2.65), testthat, covr
RoxygenNote: 6.0.1
URL: http://rlang.tidyverse.org, https://github.com/r-lib/rlang
BugReports: https://github.com/r-lib/rlang/issues
NeedsCompilation: yes
Packaged: 2018-05-30 13:14:55 UTC; lionel
Author: Lionel Henry [aut, cre], Hadley Wickham [aut], RStudio [cph]
Maintainer: Lionel Henry <lionel#rstudio.com>
Repository: CRAN
Date/Publication: 2018-05-30 14:23:07 UTC
Built: R 3.5.1; x86_64-w64-mingw32; 2018-07-02 15:08:55 UTC; windows
-- File: [redacted]/My Documents/R/win-library/3.5/rlang/Meta/package.rds
You have 3 different warnings (digest, yaml, and rlang) that each indicate that a package DLL file is corrupted. You are doing something very wrong when installing your packages.
The most common cause of this problem is trying to update a package while it is loaded in R (possibly in another process!). It could also be caused by a bad antivirus program that locks the dll which prevents it from being updated. Please try the following steps:
Quit all R/Rstudio sessions. Check in taskmgr that no Rterm or Rgui process is running.
Delete the folders yaml, rlang and digest inside Documents\R\win-library\3.5\ and also inside C:\Program Files\R\R-3.5.x\library\ if they exists there as well.
Start R to confirm they are gone. Running library(yaml) or library(rlang) should give an error e.g: there is no package called ‘yaml’. Quit R.
Start a new R and run: install.packages(c("yaml", "rlang", "digest"))
Pay close attention to the output, especially the final lines. If you see a warning like below the installation got corrupted and you should remove the package!
Answering my own question in case anyone else encounters a similar issue in the future...
Working with my work IT department we have now tied this to custom permissions on my workstation that mean that R packages can only be run to pre-specified libraries (in my case "C:\R\R-3.4.3\library").
Installing packages directly into that location fixes the issue but is not desirable for all the reasons that people might want to use custom locations (e.g. running multiple versions of the same package, keeping separate libraries for some projects).
As such there are two solutions that may be more or less attainable given your own IT system.
Convince your IT department to relax the permissions for R packages
to allow custom library locations.
Give up and run everything from the "permitted" library location (e.g. C:\R\R-3.4.3\library)
Raise a support ticket every time you need to install a package into a custom location and hope that IT eventually gives in.
This sort of problems almost always comes from a bug in R on Windows: If you reinstall a package that includes compiled code, and if that package is already loaded in R, the DLL will not get updated.
Please try reinstalling rlang on a fresh session. Sometimes packages get loaded automatically at startup from .RProfile and you can check this by calling sessionInfo() after starting up.

Sentiment Analysis using R: github 'okugami79/sentiment140' package installation error

I wish to install sentiment140 github package by developer okugami79. I wrote following script for the same:
install.packages("githubinstall")
require(devtools)
library(githubinstall)
install_github('sentiment140', 'okugami79')
library(sentiment)
But it threw an error:
Installation failed: Failed to connect to raw.githubusercontent.com port 443: Timed out
Warning message: Username parameter is deprecated. Please use okugami79/sentiment140
Then I modified installation statement as follows:
install_github('okugami79/sentiment140')
Still it threw an error:
Installation failed: Failed to connect to raw.githubusercontent.com port 443: Timed out
I checked for solution on stackoverflow through following link:
Timeout R package installation from Github
Here, I found a way to install github package by downloading package zip file and installing it in R using:
install.packages("/address/to/zip-package", repos = NULL, type="source")
This also prompts error:
Warning: invalid package 'sentiment-master'
Error: ERROR: no packages specified
Warning in install.packages :
running command '"C:/PROGRA~1/R/R-33~1.3/bin/x64/R" CMD INSTALL -l "C:\Users\u257449\Documents\R\win-library\3.3" "sentiment-master"' had status 1
Warning in install.packages : installation of package ‘sentiment-master’ had non-zero exit status
How should I go about installing required package from github in R ? Your valuable advice/solution is requested.
Thank You !
Just a straightforward pair of functions installed this package from Github source for me on both Windows and OSX.
install.packages("devtools")
devtools::install_github('okugami79/sentiment140')
There may be something unusual about your system setup, in which case, it would be helpful to have your session information. You can get that by entering sessionInfo().
However, note that this package you are looking to install is over 4 years old per the description file on Github. A lot of work has gone into other packages that work with natural language processing and sentiment analysis. The CRAN Task View for Natural Language Processing is a good place to start for an overview of many of these packages that can be installed directly from CRAN. There are many resources that are better maintained. For example, here's a chapter on sentiment analysis using the tidytext package.

Error in in installing an old version of a R package

I tryed to install from file an old version of RgoogleMaps package with this command
install.packages("F://RgoogleMaps_1.1.9.15.tar.gz", repos = NULL, type="source")
but i found this error message:
* installing *source* package 'RgoogleMaps' ...
** package 'RgoogleMaps' successfully unpacked and MD5 sums checked
ERROR: a 'NAMESPACE' file is required
* removing 'C:/Users/Famiglia Mazza/Documents/R/win-library/3.1/RgoogleMaps'
* restoring previous 'C:/Users/Famiglia Mazza/Documents/R/win-library/3.1/RgoogleMaps'
Warning in install.packages :
running command '"C:/PROGRA~1/R/R-31~1.2/bin/x64/R" CMD INSTALL -l "C:\Users\Famiglia Mazza\Documents\R\win-library\3.1" "F://RgoogleMaps_1.1.9.15.tar.gz"' had status 1
Warning in install.packages :
installation of package ‘F://RgoogleMaps_1.1.9.15.tar.gz’ had non-zero exit status
what can I do? I'm using R on Windows
In R 2.14.0 a requirement was made that all packages had namespaces, but as a transitional arrangement those that didn't would have one automatically generated at install time.
A package R code but without a ‘NAMESPACE’ file will have a default
one created at R CMD build or R CMD INSTALL time, so all packages will
be installed with namespaces. A consequence of this is that
.First.lib() functions need to be copied to .onLoad() (usually) or
.onAttach(). For the time being, if there is an auto-generated
‘NAMESPACE’ file and no .onLoad() nor .onAttach() function is found
but .First.lib() is, it will be run as the attach hook (unless the
package is one of a list of known exceptions, when it will be run as
the load hook).
However, by R 3.0.0 this transitional arrangement was ended:
The transitional support for installing packages without namespaces
(required since R 2.14.0) has been removed. R CMD build will still add
a namespace, but a .First.lib() function will need to be converted.
R CMD INSTALL no longer adds a namespace (so installation will fail),
and a .First.lib() function in a package will be ignored (with an
installation warning for now).
As an exception, packages without a ‘R’ directory and no ‘NAMESPACE’
file can still be installed.
Therefore, I suggest you use an older version of R to run this package. One prior to R 3.0.0 should suffice, and the latest one prior to that is R 2.15.3.

problem when installing RTextTools for R

I was trying to install RTextTools package for R, but failed. Here is the output from the screen
> > install.packages("RTextTools")
Warning in install.packages("RTextTools") :
argument 'lib' is missing: using 'C:\Users\datamining\Documents/R/win-library/2.10'
--- Please select a CRAN mirror for use in this session ---
Warning: unable to access index for repository http://www.stats.ox.ac.uk/pub/RWin/bin/windows/contrib/2.10
Warning message:
In getDependencies(pkgs, dependencies, available, lib) :
package ‘RTextTools’ is not available
What's the reason for this problem, and how to fix it? Thanks.
There are two distinct, but related, issues:
You are running version 2.10 of R which is two years old. CRAN supports only the current version with pre-built binaries. You could try installing from source.
RTextTools, as can be seen on its CRAN page also requires at least R version 2.13.
So in short: you should upgrade.
I have resolved the issue. I have Download RTextTools From Given Link.

https://cran.r-project.org/src/contrib/Archive/RTextTools/
and copy RTextTools_1.4.2.tar.gz file in project root folder then run this command in project folder in terminal
"R CMD INSTALL RTextTools_1.4.2.tar.gz"
After running this command I receive below error
"ERROR: dependencies ‘SparseM’, ‘randomForest’, ‘tree’, ‘e1071’, ‘ipred’, ‘caTools’, ‘maxent’, ‘glmnet’, ‘tau’ are not available for package ‘RTextTools’".
Now install each dependencies from RStudio or RConsole (Any Editor used by you) by simply running this code.
install.packages("caTools").
Install all 9 required packages One By One (In My Case it was 9 Packages Dependencies required by RTextTools) all packages will be installed except 'maxent'.
Now download maxent from the given link.
https://cran.r-project.org/src/contrib/Archive/maxent/.
and copy maxent_1.3.3.1.tar file in project folder then run this command in project folder in terminal.
"R CMD INSTALL maxent_1.3.3.1.tar"
Now For RTextTools Run this command again in Terminal.
"R CMD INSTALL RTextTools_1.4.2.tar.gz"
All is done Now..
But the Last Step is
Load the RTextTools using.
library(RTextTools)
You will see one more Error: Load SparseM Now Loading SparseM use code below.
library(SparseM)
and in the last Load RTextTools
library(RTextTools)
RTextTools is dependent on a number of packages, most of which require R 2.13+. You should always keep R updated to the latest version, since each update contains numerous bug fixes and performance enhancements.
If you can't install packages from repository or the packages are not available anymore, just follow this steps:
Install.packages("devtools")
check -- library("devtools")
install_github("cran/maxent")
install_github("cran/RTextTools")

Resources