-
-
Save BroVic/7771e1e86df35f6410a3f586ea1ef6c6 to your computer and use it in GitHub Desktop.
.Rhistory |
# IMPORTANT UPDATE!!! | |
# THIS SCRIPT STANDS ARCHIVED AS IT HAS BEEN OVERTAKEN BY EVENTS | |
# IN THE SPACE, NOTABLY THE ARCHIVING OF RGTK2 ON CRAN | |
# Created: 30 Jul 2020 | |
# Updated: 03 Jan 2022 | |
################################################################## | |
# gwdg-arch.R: Installation of current and archived packages # | |
# upon which the RQDA package depends. The key # | |
# packages mentioned are RGtk2, gWidgets, # | |
# # | |
# HOW TO USE THIS SCRIPT: # | |
# This file should be run at the command line or in an # | |
# interactive R session i.e. in the R console, as follows: # | |
# * Windows command line (CMD or PowerShell) # | |
# Rscript.exe gwdg-arch.R [--args verbose] # | |
# # | |
# * R console # | |
# source('gwdg-arch.R') # | |
# # | |
# IMPORTANT NOTICE!!! # | |
# Please BE aware that if Gtk+ is not properly installed, this # | |
# script will stop and require the user to open an R session # | |
# to install it. Once this is done, this script should be run # | |
# again to complete the installation of the packages that # | |
# directly or indirectly depend on it. # | |
# # | |
################################################################## | |
local({ | |
# --- | |
cArg <- commandArgs(trailingOnly = TRUE) | |
cArg <- cArg[length(cArg)] | |
# --- | |
## Provides the index to CRAN directory | |
cran.index <- function() { | |
c("https://cran.r-project.org") | |
} | |
## Returns the address to RStudio's CRAN mirror | |
rstudio <- function() { | |
c('https://cran.rstudio.com') | |
} | |
local_gtk_bin_path <- function(pkg = 'RGtk2') { | |
gtkdir <- file.path(.libPaths()[1], pkg, 'gtk') | |
file.path(gtkdir, .Platform$r_arch) | |
} | |
shellQuiet <- TRUE | |
if (length(cArg) != 0) { | |
if (cArg == "verbose") | |
shellQuiet <- FALSE | |
} | |
## Installs initial packages required by the script. | |
## What makes these ones special is that they are | |
## current package versions from CRAN and they are | |
## downloaded as binaries. | |
## @param cranry A character vector of packages. | |
.install_init <- function(cranbry) { | |
stopifnot(is.character(cranbry)) | |
tryCatch({ | |
notInstalled <- | |
cranbry[!cranbry %in% .packages(all.available = TRUE)] | |
install.packages(notInstalled, repos = rstudio(), quiet = !shellQuiet) | |
}, error = function(e) { | |
stop(sprintf( | |
"Initialization failed. Install %s", | |
paste(cranbry, collapse = ', ') | |
)) | |
}) | |
} | |
## Checks the availability of Rtools on Windows (v35) | |
.check_buildtools <- function() { | |
if (!devtools::has_devel()) { | |
if (.Platform$OS.type == 'windows') { | |
toolsUrl <- | |
file.path(cran.index(), | |
"bin", | |
.Platform$OS.type, | |
"Rtools/history.html") | |
errBuildtools <- | |
sprintf("Build tools were not found. Please visit %s to install.", | |
toolsUrl) | |
stop(errBuildtools, call. = TRUE) | |
} | |
} | |
} | |
.install_init(c('devtools', 'cairoDevice', 'igraph')) | |
.check_buildtools() | |
## Installs a given CRAN archive | |
## @param name Name of the package | |
## @param ver The package version | |
inst <- function(name, ver) { | |
rgtk2 <- "RGtk2" | |
archOpts <- "--no-multiarch" | |
isRGtk2 <- name == rgtk2 | |
pkgExists <- quote(name %in% .packages(all.available = TRUE)) | |
if (isRGtk2) { | |
msgRGtk2 <- | |
list( | |
line1 = "Installing 'RGtk2'. If it fails, use `install.packages` in R console ... ", | |
line2 = "Run `library(RGtk2)` in R to install Gtk+. Then, rerun this script." | |
) | |
# Custom error condition | |
abortRgtk2 <- function() { | |
msg <- | |
sprintf("Could not install %s. Try doing so in R console", rgtk2) | |
stop(msg, call. = FALSE) | |
} | |
## Install RGtk2 | |
if (!eval(pkgExists)) { | |
message(msgRGtk2$line1, appendLF = !shellQuiet) | |
tryCatch({ | |
install.packages( | |
rgtk2, | |
repos = rstudio(), | |
INSTALL_opts = archOpts, | |
quiet = shellQuiet, | |
verbose = shellQuiet | |
) | |
message("Done") # Per RGtk2/R/zzz.R, Gtk+ can only be installed interactively. | |
}, | |
error = function(e) { | |
message("Failed") | |
abortRgtk2() | |
}, | |
warning = function(w) { | |
wrnmsg <- "cannot remove prior installation of package 'RGtk2'" | |
if (conditionMessage(w) == wrnmsg) | |
abortRgtk2() | |
}, | |
finally = return(message(msgRGtk2$line2))) | |
} | |
} | |
## Avoid repeat installations via an early return | |
## If we're dealing with RGtk2, just stop the script | |
## and install Gtk+ interactively, if it is required. | |
if (eval(pkgExists)) { | |
message(sQuote(name), " is already installed") | |
if (isRGtk2) { | |
if (!dir.exists(local_gtk_bin_path(rgtk2))) { # Consider: Directory may be a dud. | |
message(msgRGtk2$line2) | |
stop('Execution stopped.', call. = FALSE) | |
} | |
} | |
return() | |
} | |
## Grab the package archives as desired. | |
## When installing them, the following are considered: | |
## => asking for upgrade interrupts installation | |
## => install only one of 32- or 64-bit, not both | |
## But first, if RGtk2 is not present, there's no | |
## point trying to install packages that depend on it. | |
isRgtkDep <- (name == 'gWidgetsRGtk2' || name == 'RQDA') | |
rgtkNotReady <- !(rgtk2 %in% .packages(all.available = TRUE) && | |
dir.exists(local_gtk_bin_path(rgtk2))) | |
if (isRgtkDep && rgtkNotReady) { | |
message(sQuote(name), " was not installed because RGtk2 is not ready") | |
return() | |
} | |
tryCatch({ | |
msg <- sprintf("Installing '%s' ... ", name) | |
message(msg, appendLF = !shellQuiet) | |
if (!isRGtk2) | |
devtools::install_version( | |
name, | |
ver, | |
repos = cran.index(), | |
quiet = shellQuiet, | |
upgrade = "never", | |
INSTALL_opts = archOpts | |
) | |
message("Done") | |
}, | |
error = function(e) { | |
message("Failed") | |
}) | |
} # end inst() | |
pkgversions <- c(RGtk2 = "2.20.36", | |
gWidgets = '0.0-54.2', | |
gWidgetsRGtk2 = '0.0-86', | |
RQDA = '0.3-1') | |
invisible(Map(inst, names(pkgversions), pkgversions)) | |
}) | |
# Used successfully with R 4.0.3 |
Hi @BroVic,
Many thanks it worked!!!
You're welcome!
Hi BroVic,
Thanks for the script.
Error: .onLoad failed in loadNamespace() for 'pkgload', details:
call: NULL
error: package ‘testthat’ does not have a namespace
Called from: runHook(".onLoad", env, package.lib, package)
Do you have a idea? I appreciate your help!
Poh
run sessionInfo( )
output
R version 4.0.3 (2020-10-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19041)
Matrix products: default
locale:
[1] LC_COLLATE=English_Malaysia.1252 LC_CTYPE=English_Malaysia.1252 LC_MONETARY=English_Malaysia.1252
[4] LC_NUMERIC=C LC_TIME=English_Malaysia.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] gWidgets_0.0-54.2 RGtk2_2.20.36
loaded via a namespace (and not attached):
[1] prettyunits_1.1.1 ps_1.5.0 rprojroot_2.0.2 withr_2.4.1 crayon_1.4.1 assertthat_0.2.1
[7] R6_2.5.0 rlang_0.4.10 cachem_1.0.1 cli_2.3.0 remotes_2.2.0 callr_3.5.1
[13] ellipsis_0.3.1 desc_1.2.0 tools_4.0.3 glue_1.4.2 processx_3.4.5 fastmap_1.1.0
[19] compiler_4.0.3 pkgbuild_1.2.0 memoise_2.0.0
Hi @poh58
pkgload
is a dependency of devtools, so perhaps you should install devtools again. In any case, I just released a package to help with this installation. Perhaps you might like to try it out. https://github.com/BroVic/RQDAassist
@BroVic
Thank you for the advise. The package is now running smoothly on my system!
Cheers
Poh
Fantastic! Cheers.
Thank you for your contribution trying to get this to work.
I received the following output error inputting into the R studio terminal:
$ Rscript gwdg-arch.R --args verbose
Error in get(genname, envir = envir) : object 'testthat_print' not found
Your system is ready to build packages!
'RGtk2' is already installed
'gWidgets' is already installed
Installing 'gWidgetsRGtk2' ...
Downloading package from url: https://cran.r-project.org/src/contrib/Archive/gWidgetsRGtk2/gWidgetsRGtk2_0.0-86.tar.gz
Installing package into 'C:/Users/me/Documents/R/win-library/4.0'
(as 'lib' is unspecified)
* installing *source* package 'gWidgetsRGtk2' ...
** package 'gWidgetsRGtk2' successfully unpacked and MD5 sums checked
** using staged installation
** R
** inst
** byte-compile and prepare package for lazy loading
Error: (converted from warning) package 'RGtk2' was built under R version 4.0.3
Execution halted
ERROR: lazy loading failed for package 'gWidgetsRGtk2'
* removing 'C:/Users/me/Documents/R/win-library/4.0/gWidgetsRGtk2'
Failed
Installing 'RQDA' ...
Downloading package from url: https://cran.r-project.org/src/contrib/Archive/RQDA/RQDA_0.3-1.tar.gz
Installing package into 'C:/Users/me/Documents/R/win-library/4.0'(as 'lib' is unspecified)
ERROR: dependency 'gWidgetsRGtk2' is not available for package 'RQDA'
* removing 'C:/Users/me/Documents/R/win-library/4.0/RQDA'
Failed
Hi @alxoka,
Did you install Gtk+ by running library(RGtk2)
? I also noticed that your terminal has a bash prompt? What OS are you running - perhaps you could provide me with the output of sessionInfo()
so I can take a closer look and try to reproduce your error.
Hello,
EDIT: I fixed it! Thank you!! By checking library(RGtk2) I realized my R version 4.0.2 was below what RGtk2 was built on (4.0.3). I updated R to 4.0.4, loaded library(RGtk2)
in R studio, then Rscript gwdg-arch.R --args verbose
in the terminal of R Studio and it worked!
I think I installed Gtk+ and ran library(RGtk2)
Here is my sessionInfo()
. I am using Windows 10 x64. I'm not too sure what is the difference between bash and non bash prompt or the significance of that.
> library(RGtk2)
> sessionInfo()
R version 4.0.2 (2020-06-22)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19042)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets
[6] methods base
other attached packages:
[1] RGtk2_2.20.36
loaded via a namespace (and not attached):
[1] compiler_4.0.2 tools_4.0.2
>
Additionally,
R version 4.0.2 (2020-06-22) -- "Taking Off Again"
Copyright (C) 2020 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (64-bit)
Fantastic!
The bash prompt is found in the default system shell for major Linux distributions (Bourne-again shell). But you said you ran it in the R Studio terminal. So on Windows 10, your terminal is probably running on Git-Bash or Windows Subsystem for Linux (WSL), if installed.
Cheers!
Hi @Ma-Se-collab,
I edited the script somewhat because when I tested it I ran into a similar error. The API must have changed somewhat and it was installing igraph package as source files. The error was due to a compilation failure which, I think, is linked to the option chosen to install for only ONE architecture. The script now installs igraph separately as binary and it works for me. We have similar
sessionInfo()
s.At any rate, if you run into an issue with the script, add the
--verbose
flag so that one can see the source of the error more clearly.