Skip to content

Commit

Permalink
Improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Adafede committed Jul 3, 2024
1 parent 9af7d88 commit d1d2cfb
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 117 deletions.
112 changes: 4 additions & 108 deletions R/install_latest_version.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,132 +2,28 @@
#'
#' @description This function installs the latest version
#'
#' @param test Flag for test
#'
#' @return NULL
#'
#' @export
#'
#' @examples NULL
install_latest_version <- function(test = FALSE) {
install_latest_version <- function() {
options(repos = c(CRAN = "https://cloud.r-project.org"))
if (Sys.info()[["sysname"]] == "Windows") {
message("You should install RTools if not already done")
}
if (Sys.info()[["sysname"]] == "Linux") {
system(command = "sudo apt install libcurl4-openssl-dev")
}
if (!requireNamespace("pak", quietly = TRUE)) {
lib <- Sys.getenv("R_LIBS_SITE")
if (lib == "") {
lib <- file.path(dirname(.Library), "site-library")
cat(sprintf("R_LIBS_SITE=%s\n", lib), append = TRUE)
cat(sprintf("R_LIB_FOR_PAK=%s\n", lib), append = TRUE)

message("Setting R_LIBS_SITE to ", lib)
} else {
message("R_LIBS_SITE is already set to ", lib)
cat(sprintf(
"R_LIB_FOR_PAK=%s\n",
strsplit(lib, .Platform$path.sep)[[1]][[1]]
), append = TRUE)
}
install.packages(
"pak",
repos = sprintf(
"https://r-lib.github.io/p/pak/stable/%s/%s/%s",
.Platform$pkgType,
R.Version()$os,
R.Version()$arch
)
)
if (!requireNamespace("devtools")) {
install.packages("devtools")
}
ref <- ifelse(
test = Sys.getenv("BRANCH_NAME") != "",
yes = Sys.getenv("BRANCH_NAME"),
no = "main"
)
pak::pak_cleanup(force = TRUE)
pak::pak_update()
if (!requireNamespace(c("timaR"), quietly = TRUE)) {
message("Installing for the first time...")
local_version <- "myFirstInstallTrickToWork"
} else {
local_version <- pak::pkg_status("timaR")$version[1]
}
# TODO not ideal
remote_version <- readLines(
"https://raw.githubusercontent.com/taxonomicallyinformedannotation/tima-r/main/DESCRIPTION"
)[[3]] |>
gsub(
pattern = "Version: ",
replacement = "",
fixed = TRUE
)
if ((local_version == remote_version) && (test == FALSE)) {
message(
"You already have the latest version (",
local_version,
") skipping"
)
} else {
pak::pak_update()
pak::pak(ask = FALSE, upgrade = TRUE)
# Try installing the local version first
success <- tryCatch(
{
message("Installing local version")
pak::pkg_install(
pkg = ".",
ask = FALSE,
upgrade = FALSE
)
return(test == FALSE)
},
error = function(e) {
return(FALSE)
}
)
# If local version installation fails, try the URL from DESCRIPTION file
if (!success) {
success <- tryCatch(
{
message("Installing local version from URL")
pak::pkg_install(
pkg = desc::desc_get_urls()[[1]],
ask = FALSE,
upgrade = FALSE
)
return(test == FALSE)
},
error = function(e) {
return(FALSE)
}
)
}
# If URL installation fails, try installing the remote version from GitHub
if (!success) {
success <- tryCatch(
{
message("Installing remote version")
pak::pkg_install(
pkg = "taxonomicallyinformedannotation/tima-r",
ask = FALSE,
upgrade = FALSE
)
return(test == FALSE)
},
error = function(e) {
message("Install failed")
return(FALSE)
}
)
}
# Final message if all attempts fail
if (!success) {
message("All installation attempts failed")
}
}
devtools::install_github(repo = paste0("taxonomicallyinformedannotation/tima-r@", ref))
cache <- fs::path_home(".tima")
message("Creating cache at ", cache)
fs::dir_create(path = cache)
Expand Down
2 changes: 1 addition & 1 deletion codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@
"SystemRequirements": null
},
"keywords": ["metaboliteannotation", "chemotaxonomy", "scoringsystem", "naturalproducts", "computationalmetabolomics", "taxonomicdistance", "specializedmetabolome"],
"fileSize": "4379.43KB",
"fileSize": "4376.027KB",
"citation": [
{
"@type": "ScholarlyArticle",
Expand Down
5 changes: 1 addition & 4 deletions man/install_latest_version.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions tests/testthat/test-functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ library(testthat)
## need to do all in one because of outputs needed in the same temp dir
## use fixtures instead in the future
test_that(desc = "Test functions", code = {
install_latest_version(test = TRUE)
install_latest_version()
setwd(fs::path_home(".tima"))
## Prepare parameters
paths <- parse_yaml_paths()
params <- get_params(step = "prepare_params")
Expand Down Expand Up @@ -662,6 +663,3 @@ test_that(desc = "Test functions", code = {

succeed()
})

## See https://github.com/markfairbanks/tidytable/issues/269
.datatable.aware <- TRUE

0 comments on commit d1d2cfb

Please sign in to comment.