Error when trying to install package from GitHub
You have not yet created a package. You've just created some files with R code in them. An R package has a very particular structure that includes things like a DESCRIPTION file and a NAMESPACE file. In theory you could create these yourself, but often it's easier to use things like devtools::create
and roxygen
to create them for you. Or if you are using RStudio, you can create a new R Package project with default versions of these files.
To add a DESCRIPTION File, try running
usethis::use_description()
That will fill in defaults you can change.
Then you will need to create a NAMESPACE file. If you just want to make all the functions you define inside your R files to be available outside the pacakge, you can just put
exportPattern("^[[:alpha:]]+")
in that file and that should work.
You might also consider following guides like thoses http://r-pkgs.had.co.nz/package.html or https://swcarpentry.github.io/r-novice-inflammation/08-making-packages-R/ for a better overview on creating a package.
Once your repo looks like a proper R package, then you can use devtools::install_github
to install it.
Note that github can be useful for tracking changes to any types of files. You may perform an analysis in an R script that you would like to track changes for and save that on github but it may not make sense to turn that analysis script into a packages. You generally make packages when you want to reuse functions or data across different projects then those projects can install and load your package. So not all R code lives inside an R package, but devtools::install_github
can only be used to install actual packages.
R Unable to Install Packages From GitHub (System Error 267 @win/processx.c:1040)
The standalone mode of the remotes package solved the issue for me,
as suggested by the maintainer of processx (Gábor Csárdi) here
devtools::install_github()
only calls remotes::install_github()
.
However, for the remotes, there is the option to be exectued in standalone mode
Source: Cran
Standalone mode
remotes will use the curl, git2r and pkgbuild packages if they are
installed to provide faster implementations for some aspects of the
install process. However if you are using remotes to install or update
these packages (or their reverse dependencies) using them during
installation may fail (particularly on Windows).If you set the environment variable R_REMOTES_STANDALONE="true" (e.g.
in R Sys.setenv(R_REMOTES_STANDALONE="true")) you can force remotes to
operate in standalone mode and use only its internal R
implementations. This will allow successful installation of these
packages
With the following lines of code, gt was finally successfull installed from github.
Sys.setenv(R_REMOTES_STANDALONE="true")
remotes::install_github("rstudio/gt")
Thanks all the commentators for your help!
Update October / 2021
To avoid having to do these steps (Set in standanlone mode, and install with remotes) over and over again everytime you want to install a new package from github another convenient workaround is to just rollback to the previous version of processx
as adviced by @rempsy in the github issue:
install.packages("pacman")
pacman::p_del(processx)
# Installing previous verison 3.5.1
install.packages("https://cran.r-project.org/src/contrib/Archive/processx/processx_3.5.1.tar.gz", repos=NULL, type="source")
After the rollback of processx to version 3.5.1
, devtools::install_github()
works as expected, e.g.
devtools::install_github("rstudio/gt")
Error installing packages from github
from : http://healthvis.org/install/
Some users have run into the following error when using the instructions above: Error in function (type, msg, asError = TRUE) : couldn't connect to host. This is likely due to the use of proxies (which would prevent you from installing any package from github), and can be rectified using the httr package. Run the following commands before install_github(...) above:
install.packages("httr")
library(devtools)
library(httr)
set_config(use_proxy(url="http://proxyname.company.com",port=8080,username="XXX",password="XXX"))
install_github("cranvas")
Hope this helps.
Related Topics
Changing Word Template for Knitr in Rmarkdown
How to Select All Unique Combinations of Two Columns in an R Data Frame
Format Latitude and Longitude Axis Labels in Ggplot
Add Rows to Grouped Data with Dplyr
Getting a Slot's Value of S4 Objects
Ggplot2 Aes_String() Fails to Handle Names Starting with Numbers or Containing Spaces
Faster Way to Find the First True Value in a Vector
Left_Join Two Data Frames and Overwrite
Create Multilines from Points, Grouped by Id with Sf Package
Can Lapply Not Modify Variables in a Higher Scope
S3 Method Consistency Warning When Building R Package with Roxygen
Use a Factor Column in "By" and Do Not Drop Empty Factors
Dplyr Filter() with SQL-Like %Wildcard%
Saving a Data Frame as a Binary File