Cannot install my created packages - r

I've been writing a lot of code for my personal use and finally reached a point where I realised I should really be including this all in a package which I can load in instead of copy and pasting it in each time.
I followed the following tutorial for the creation of a basic package.
https://hilaryparker.com/2014/04/29/writing-an-r-package-from-scratch/
As far as I can tell everything went well with the actual creation element. Here are screenshots of the result:
The cats folder:
The /cats/R folder
The /cats/man folder
The problem comes when I want to run the line:
install("cats")
When I try to do that I get the following error:
Installing cats
"C:/PROGRA~1/R/R-33~1.1/bin/x64/R" --no-site-file --no-environ --no-save --no-restore --quiet CMD INSTALL "/Documents/cats" --library="C:/Users/Aodhán/Documents/R/win-library/3.3" --install-tests
* installing *source* package 'cats' ...
Warning in file(file, if (append) "a" else "w") :
cannot open file 'C:/Users/Aodhán/Documents/R/win-library/3.3/cats/DESCRIPTION': No such file or directory
Error in file(file, if (append) "a" else "w") :
cannot open the connection
ERROR: installing package DESCRIPTION failed for package 'cats'
* removing 'C:/Users/Aodhán/Documents/R/win-library/3.3/cats'
Error: Command failed (1)
This error happens for my own package, but it also happens if I run the command:
devtools::install_github("klutometis/roxygen")
Any advice would be appreciated.
EDIT: Could it be that my username contains the character á in it?
EDIT 2:The DESCRIPTION file is:
Package: cats
Title: What the Package Does (one line, title case)
Version: 0.0.0.9000
Authors#R: person("First", "Last", email = "first.last#example.com",
role = c("aut", "cre"))
Maintainer: Aodhán O'Leary
Author: Aodhán O'Leary [aut, cre]
Description: What the package does (one paragraph).
Depends: R (>= 3.3.1)
License: What license is it under?
Encoding: UTF-8
LazyData: true
RoxygenNote: 6.0.1
Sys.getenv("R_HOME") returns "C:/PROGRA~1/R/R-33~1.1"
Sys.getenv("R_LIBS_USER") returns "C:\Users\Aodhán\Documents/R/win-library/3.3"
Sys.getenv("R_HOME") returns "C:\Users\Aodhán\Documents"
devtools::build("cats") creates "cats_0.0.0.9000.tar.gz"
install.packages("../cats_version.tar.gz") returns the same error as above
Note: This is on a Win10 machine, using R 3.3.1, which I apologise for not mentioning up top. I was quite tired when writing the post yesterday.
Edit 3: Here's the result of using the following commands: R CMD build cats followed by R CMD check cats
00check:
using log directory 'C:/Users/Aodhán/Documents/cats.Rcheck'
using R version 3.3.1 (2016-06-21)
using platform: x86_64-w64-mingw32 (64-bit)
using session charset: ISO8859-1
checking for file 'cats/DESCRIPTION' ... OK
this is package 'cats' version '0.0.0.9000'
package encoding: UTF-8
checking package namespace information ... OK
checking package dependencies ... OK
checking if this is a source package ... OK
checking if there is a namespace ... OK
checking for .dll and .exe files ... OK
checking for hidden files and directories ... NOTE Found the following hidden files and directories: .gitignore These were most
likely included in error. See section 'Package structure' in the
'Writing R Extensions' manual.
checking for portable file names ... OK
checking whether package 'cats' can be installed ... ERROR Installation failed. See
'C:/Users/Aodhán/Documents/cats.Rcheck/00install.out' for details.
DONE
Status: 1 ERROR, 1 NOTE
00install.out
installing source package 'cats' ...
Warning in file(file, if (append) "a" else "w") :
cannot open file 'C:/Users/Aodhan/Documents/cats.Rcheck/cats/DESCRIPTION':
No such file or directory
Error in file(file, if (append) "a" else "w") :
cannot open the connection
ERROR: installing package DESCRIPTION failed for package 'cats'
removing 'C:/Users/Aodhán/Documents/cats.Rcheck/cats'

The problem was the special character in my name, á. When I put it in the C:\ directory and ran R CMD build cats and R CMD check cats it passed that error (though there was an error later on with the pdf - I'll see if I can resolve that myself).
I'll try and post this as a bug. Moderately annoying. Should have thought of that test earlier.

I've run into this problem recently (R version 3.5.2) on two different computers. I don't have the full, exact error message right now, but it contained the following two snippets:
Error in writeLines(paste0(c(out[is_not_empty]), eor), file, useBytes = useBytes) :
(converted from warning) invalid char string in output conversion
and
ERROR: installing package DESCRIPTION failed for package
The problem, I believe, was the existence of special characters in my .Rprofile file. I'd been meaning to get rid of that file anyway (for the sake of reproducibility), and doing so fixed the problem.
To do this in R, the code below will (1) copy your .Rprofile and save it as .Rprofile-old (in case you want to use/restore it later on) and then (2) delete your .Rprofile.
## copy backup of .Rprofile
file.copy("~/.Rprofile", "~/.Rprofile-old")
## delete .Rprofile
unlink("~/.Rprofile")
Once you've run the above code, restart R and the problem will [hopefully] be fixed!

Installing source package..
It is important to specify repo and type
Convert package into package_name.tar.gz
Get into project environment by double clicking the .Rproj file in
your project and click on build -> Build Source Package to build tar.gz file
install.packages("full_path/package_name.tar.gz", repo = NULL, type =
"source")

Related

Cannot install vignette from an R package on GitHub

I coded an R package that is hosted on my GitHub. I included a vignette, and I can install the package and load the vignette without any issue from R and RStudio by doing:
devtools::install_github("rosalieb/serac", build_vignettes = TRUE)
library(serac)
vignette("serac")
However, I have a few colleagues who cannot install the vignette (the only way they can download the package is by doing devtools::install_github("rosalieb/serac") (default of build_vignettes is FALSE).
It works if they use RStudio, but not in 'regular' R.
I encourage people to use RStudio, but I cannot force them, and eventually, I do not understand why it would work in 'regular' R for me but not for them.
They tried to install pandoc, knitr, Rtools - none of these worked.
Here is the error message when my colleague tries to install the package with the vignette:
v checking for file 'C:\Temp\RtmpO8YwVb\remotesf9842f1431\rosalieb-serac-46a3587/DESCRIPTION'
- preparing 'serac':
checking DESCRIPTION meta-information ...
checking DESCRIPTION meta-information ...
v checking DESCRIPTION meta-information
- installing the package to build vignettes
creating vignettes ...
creating vignettes ...
E creating vignettes (4.9s)
--- re-building 'serac.Rmd' using rmarkdown
Error: processing vignette 'serac.Rmd' failed with diagnostics:
Pandoc is required to build R Markdown vignettes but not available. Please make sure it is installed.
--- failed re-building 'serac.Rmd'
RESUME : le traitement du fichier suivant a échoué :
'serac.Rmd'
Erreur : Vignette re-building failed.
Exécution arrêtée
Erreur : Failed to install 'serac' from GitHub:
System command 'Rcmd.exe' failed, exit status: 1, stdout & stderr were printed
Thanks in advance for your help!
The message indicates that rmarkdown::render can't find Pandoc.
It looks for it in three places: in the directory specified by the RSTUDIO_PANDOC environment variable, in directories on the PATH, in the directory opt/pandoc in the user's home directory. So your colleagues who have installed it should make sure it is available in one of those locations. They can see the current values of the environment variables by running
Sys.getenv("PATH")
and
Sys.getenv("RSTUDIO_PANDOC")
Temporary changes can be made using
Sys.setenv(RSTUDIO_PANDOC="/path/to/pandoc/directory")
This needs to happen in the session that is trying to install the package and build the vignette, not in the vignette itself.
How to make permanent changes to those values depends on the details of what system they are running.

Problems when installing the broom package

I can not install the broom package. When I try I get this Error Message, that I can't understand:
installing source package 'broom' ...
** package 'broom' successfully unpacked and MD5 sums checked
** using staged installation
Warning in file(file, if (append) "a" else "w") :
cannot open file 'C:/Users/AndrisLagerlvf/Documents/R/win-library/3.6/00LOCK-broom/00new/broom/DESCRIPTION': No such file or directory
Error in file(file, if (append) "a" else "w") :
cannot open the connection
ERROR: installing package DESCRIPTION failed for package 'broom'
removing 'C:/Users/AndrésLagerlöf/Documents/R/win-library/3.6/broom'
Warning in install.packages :
installation of package ‘broom’ had non-zero exit status
I am using a Widows computer with Windows Version 1909 (OS-version 18363.657), and RStudio Version 1.2.5033, and R version 3.6.2.
When I update some packages it works fine, but when I try to update other packages I get similar error messages as above.
Further notes: I used to have the broom package installed, and tried to update the package but when I got the error message I uninstalled the package and then tried to install the package again, but got the same error message, so now I don't have access to the package.
Any suggestions on how to fix would be great! Thanks!
Check out/notice the difference between
C:/Users/AndrisLagerlvf/Documents/R/win-library/3.6
and
'C:/Users/AndrésLagerlöf/Documents/R/win-library/3.6/broom
That is (international) Encoding showing its ugly face.
I would suggest the following as a solution and also a quite common good practice.
Create a (most probably local) directory somewhere you have "good" access to that DOES NOT contain any exotic characters (eg C:\R-PKGS\win-library\3.6) then set this as your standard library path
.libPaths(c("C:/R-PKGS/win-library/3.6", .libPaths())) #watch out for the direction of the slashes (normal ones - not backslashes, since this is R code)
Put the above line into a/your ~/.Rprofile file eg via running file.edit('~/.Rprofile') in the Console.
Let me know if that does not help? I am curious because you mentioned that sometimes it works - my guess is that your routine works for those packages that are installed in R_HOME/library and not for those installed under your User directory, which contains the exotic characters. Additionally you could minggle around with your locale settings until R is satisfied with them, but I have not tested such a solution (yet) ... since this would involve heavy adjustments, to my locale and typeset settings (sorry for that).
Or even better if you want R to branch according to your Version ie if you have multiple subfolders for multiple differing minor R versions (eg R-3.5 and R-3.6 side by side) ie this is how my libPath setting looks like
.libPaths( c( paste0( "D:/R_LIB/", substr(getRversion(),1,3) ), .libPaths() ) )
This has the advantage compared to the ENV VAR approach that you can manage multiple R.version library subfolders ...

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.

Insallation failed on devtools::install_github("rstudio/rmarkdown")

I use R 3.4.3, And I need to install devtools::install_github("rstudio/rmarkdown"). But the following installation error comes up.
Downloading GitHub repo rstudio/rmarkdown#master
from URL https://api.github.com/repos/rstudio/rmarkdown/zipball/master
Installation failed: zip file 'C:\Users\Buster\AppData\Local\Temp\RtmpWyl4FP\file3bc6c571eec.zip' cannot be opened
Warning messages:
1: GitHub repo contains submodules, may not function as expected!
2: In utils::unzip(src, exdir = target) :
error 1 in extracting from zip file
How can I install this?
this has been resolved. I used devtools::install_url("http://cran.r-project.org/src/contrib/rmarkdown_1.9.tar.gz")
As explained in the README for rmarkdown:
If you are working within RStudio then you can simply install the
current release of RStudio (both the rmarkdown package and pandoc are
included).
If you want to use the rmarkdown package outside of RStudio then you
can install the package from CRAN as follows:
install.packages("rmarkdown")
This is a much more concise way of doing:
devtools::install_url("http://cran.r-project.org/src/contrib/rmarkdown_1.9.tar.gz")

Installing ggbiplot from github

I'm trying to install development version of ggbiplotfrom Github. During installation I'm getting the following error message:
library(devtools)
install_github("ggbiplot", "vqv")
Installing github repo(s) ggbiplot/master from vqv
Installing ggbiplot.zip from https://github.com/vqv/ggbiplot/zipball
Installing ggbiplot
* checking for file 'C:\Users\Muhammad Yaseen\AppData\Local\Temp\Rtmpsx4n5u\vqv-ggbiplot-2623d7c/DESCRIPTION' ... OK
* preparing 'ggbiplot':
* checking DESCRIPTION meta-information ... OK
* checking for LF line-endings in source and make files
* checking for empty or unneeded directories
* looking to see if a 'data/datalist' file should be added
* building 'ggbiplot_0.5.tar.gz'
cygwin warning:
MS-DOS style path detected: C:/Users/MUHAMM~1/AppData/Local/Temp/Rtmpsx4n5u/ggbiplot_0.5.tar.gz
Preferred POSIX equivalent is: /cygdrive/c/Users/MUHAMM~1/AppData/Local/Temp/Rtmpsx4n5u/ggbiplot_0.5.tar.gz
CYGWIN environment variable option "nodosfilewarning" turns off this warning.
Consult the user's guide for more details about POSIX paths:
http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
Warning: invalid package 'Yaseen/R/win-library/2.14'
Error: ERROR: cannot cd to directory 'C:/Users/Muhammad'
Error: Command failed (1)
In addition: Warning message:
running command '"C:/PROGRA~1/R/R-214~1.2/bin/i386/R" CMD INSTALL C:\Users\MUHAMM~1\AppData\Local\Temp\Rtmpsx4n5u/ggbiplot_0.5.tar.gz --library=C:/Users/Muhammad Yaseen/R/win-library/2.14' had status 1
Any idea to figure out this problem. Thanks in advance for your help and time.
Edit
After downloading from Github, also tried
install.packages("vqv-ggbiplot-2623d7c.tar.gz", repos=NULL, type="source")
which produced this error message
Installing package(s) into ‘C:/Users/Muhammad Yaseen/R/win-library/2.14’
(as ‘lib’ is unspecified)
Error in untar2(tarfile, files, list, exdir) : unsupported entry type 'g'
Warning messages:
1: running command 'C:/PROGRA~1/R/R-214~1.2/bin/i386/R CMD INSTALL -l "C:/Users/Muhammad Yaseen/R/win-library/2.14" "vqv-ggbiplot-2623d7c.tar.gz"' had status 1
2: In install.packages("vqv-ggbiplot-2623d7c.tar.gz", repos = NULL, :
installation of package ‘vqv-ggbiplot-2623d7c.tar.gz’ had non-zero exit status
It's because your Rlib path has a space in it: C:/Users/Muhammad Yasseen/R/win-library/2.14.
See how in the first error log the warning message was
running command '"C:/PROGRA~1/R/R-214~1.2/bin/i386/R" CMD INSTALL
C:\Users\MUHAMM~1\AppData\Local\Temp\Rtmpsx4n5u/ggbiplot_0.5.tar.gz
--library=C:/Users/Muhammad Yaseen/R/win-library/2.14'
had status 1
In particular, the --library=C:/Users/Muhammad Yaseen/R/win-library/2.14.
This should be --library="C:/Users/Muhammad Yaseen/R/win-library/2.14" to deal with the space.
Using install.packages takes care of the quotes for you - see how your second warning message (when you used install.packages) was
running command 'C:/PROGRA~1/R/R-214~1.2/bin/i386/R CMD INSTALL
-l "C:/Users/Muhammad Yaseen/R/win-library/2.14"
"vqv-ggbiplot-2623d7c.tar.gz"' had status 1
The -l "C:/Users/Muhammad Yasseen/R/win-library/2.14" has quote marks around it, so you don't get the same error.
I had a quick look at the install-github sources, and it constructs the R CMD INSTALL command via:
paste("CMD INSTALL ", built_path, " --library=", .libPaths()[1], sep="")
See how it doesn't surround .libPaths()[1] by double quotes in case of spaces? I'd guess that's your problem.
As to a fix - there seems to be an error using install.packages() on a tar file generated by git (as reported here). So, you can either:
change your R library location to somewhere without spaces
unzip the .tar.gz file (I don't know what software does this on Windows) and install from the extracted directories rather than the .tar.gz.
You can't unzip the .tar.gz because it cleans up that file quicker than you can grab it (I've watched it appear and get deleted again). Correct me if I'm wrong, but I also can't get devtools from github for teh same reason :S

Resources