Skip to content

Commit

Permalink
1.0.1 (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
OndrejMottl authored Oct 21, 2023
1 parent e7e940f commit a63c8dd
Show file tree
Hide file tree
Showing 5 changed files with 371 additions and 215 deletions.
2 changes: 1 addition & 1 deletion R/00_Config_file.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

# Version of the Workflow
workflow_version <-
"1.0.0"
"1.0.1"

# Set the current environment
current_env <- environment()
Expand Down
178 changes: 90 additions & 88 deletions R/___Init_project___.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,79 @@
#
#----------------------------------------------------------#

# Script to prepare all necessary components of environment to run the Project.
# Script to prepare all components of the environment to run the Project.
# Needs to be run only once

#----------------------------------------------------------#
# Step 0: Install {renv} for package management -----
#----------------------------------------------------------#

if (
"renv" %in% utils::installed.packages()
) {
library(renv)
} else {
# install package
utils::install.packages("renv")

# load the package
library(renv)
}

#----------------------------------------------------------#
# Step 1: Activate 'renv' project -----
#----------------------------------------------------------#

# NOTE: The R may ask the User to restart the session (R).
# After that, continue with the next step

renv::activate()

#----------------------------------------------------------#
# Step 0: Define package list and custom function -----
# Step 1: Install {here} for file navigation -----
#----------------------------------------------------------#

# list of all CRAN packages
package_list <-
if (
"here" %in% utils::installed.packages()
) {
library(here)
} else {
# install package
utils::install.packages("here")

# load the package
library(here)
}

#----------------------------------------------------------#
# Step 2: Synchronize package versions with the project -----
#----------------------------------------------------------#

# If there is no lock file present make a new snapshot
if (
isTRUE("library_list.lock" %in% list.files(here::here("renv")))
) {
cat("The project already has a lockfile. Restoring packages", "\n")

renv::restore(
lockfile = here::here("renv/library_list.lock")
)

cat("Set up completed. You can continute to run the project", "\n")

cat("Do NOT run the rest of this script", "\n")
} else {
cat("The project seems to be new (no lockfile)", "\n")

cat("Continue with this script", "\n")
}

#----------------------------------------------------------#
# Step 3: Install packages to the project -----
#----------------------------------------------------------#

# install all packages in the lst from CRAN
sapply(
c(
"assertthat",
"Bchron",
Expand All @@ -39,6 +102,7 @@ package_list <-
"lifecycle",
"magrittr",
"methods",
"neotoma2",
"purrr",
"qs",
"raster",
Expand All @@ -60,94 +124,32 @@ package_list <-
"utils",
"waldo",
"zip"
)
),
utils::install.packages,
character.only = TRUE
)

# define helper function
install_packages <-
function(pkgs_list) {
# install all packages in the lst from CRAN
sapply(pkgs_list, utils::install.packages, character.only = TRUE)

# install RUtilpol from GitHub
remotes::install_github(
repo = "HOPE-UIB-BIO/R-Utilpol-package",
ref = "HEAD",
quiet = FALSE,
upgrade = "ask"
)

# install neotoma2 from GitHub
remotes::install_github(
repo = "NeotomaDB/neotoma2",
quiet = FALSE,
upgrade = "ask"
)

# install RFossilpol from GitHub
remotes::install_github(
repo = "HOPE-UIB-BIO/R-Fossilpol-package@*release",
quiet = FALSE,
upgrade = "ask"
)
}
# install RUtilpol from GitHub
remotes::install_github(
repo = "HOPE-UIB-BIO/R-Utilpol-package",
ref = "HEAD",
quiet = FALSE,
upgrade = "ask"
)

# install RFossilpol from GitHub
remotes::install_github(
repo = "HOPE-UIB-BIO/R-Fossilpol-package@*release",
quiet = FALSE,
upgrade = "ask"
)

#----------------------------------------------------------#
# Step 1: Install 'renv' package -----
# Step 4: Save versions of packages -----
#----------------------------------------------------------#

utils::install.packages("renv")
renv::snapshot(
lockfile = here::here("renv/library_list.lock")
)


#----------------------------------------------------------#
# Step 2: Deactivate 'renv' package -----
#----------------------------------------------------------#

# deactivate to make sure that packages are updated on the machine
renv::deactivate()


#----------------------------------------------------------#
# Step 3: Install packages to the machine
#----------------------------------------------------------#

install_packages(package_list)


#----------------------------------------------------------#
# Step 4: Activate 'renv' project
#----------------------------------------------------------#

renv::activate()


#----------------------------------------------------------#
# Step 5: Install packages to the project
#----------------------------------------------------------#

install_packages(package_list)


#----------------------------------------------------------#
# Step 6: Synchronize package versions with the project
#----------------------------------------------------------#

library(here)

# if there is no lock file present make a new snapshot
if (
isFALSE("library_list.lock" %in% list.files(here::here("renv")))
) {
renv::snapshot(
lockfile = here::here("renv/library_list.lock")
)
} else {
renv::restore(
lockfile = here::here("renv/library_list.lock")
)
}


#----------------------------------------------------------#
# Step 7: Run the project
#----------------------------------------------------------#
cat("Set up completed. You can continute to run the project", "\n")
6 changes: 3 additions & 3 deletions renv/.gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cellar/
sandbox/
local/
library/
local/
cellar/
lock/
python/
sandbox/
staging/
Loading

0 comments on commit a63c8dd

Please sign in to comment.