-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #89 from dfe-analytical-services/renv-update
Renv update
- Loading branch information
Showing
73 changed files
with
11,094 additions
and
15,584 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,40 @@ | ||
source("renv/activate.R") | ||
# --------------------------------------------------------- | ||
# This is the .Rprofile file | ||
# | ||
# Use it to include any functions you want to run before any other code is run. | ||
# For example, using renv automatically sources its activate script to the .RProfile file | ||
# This ensures that all renv checks on package versions happens before any code is run. | ||
# | ||
# | ||
# --------------------------------------------------------- | ||
|
||
shhh <- suppressPackageStartupMessages # It's a library, so shhh! | ||
cat("Sourcing .Rprofile.", fill = TRUE) | ||
|
||
source("renv/activate.R") | ||
|
||
tidy_code <- function() { | ||
shhh(source("global.r")) | ||
shhh(tidy_code_function()) | ||
if (system.file(package = "dfeshiny") != "") { | ||
library(dfeshiny) | ||
} else { | ||
warning("dfeshiny package is not installed, please run renv::restore() to set up the necessary package environment") | ||
} | ||
|
||
# Function to run tests | ||
run_tests_locally <- function() { | ||
Sys.unsetenv("http_proxy") | ||
Sys.unsetenv("https_proxy") | ||
shhh(source("global.R")) | ||
source("global.r") | ||
# message("================================================================================") | ||
# message("== testthat ====================================================================") | ||
# message("") | ||
# shhh(testthat::test_dir("tests/testthat")) | ||
# testthat::test_dir("tests/testthat") | ||
# message("") | ||
message("================================================================================") | ||
message("== shinytest ===================================================================") | ||
message("== shinytest2 ==================================================================") | ||
message("") | ||
shhh(shinytest::testApp()) | ||
shinytest2::test_app() | ||
message("") | ||
message("================================================================================") | ||
} | ||
|
||
# Install commit-hooks locally | ||
statusWriteCommit <- file.copy(".hooks/pre-commit.R", ".git/hooks/pre-commit", overwrite = TRUE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#!/usr/bin/env Rscript | ||
cat("Running commit hooks...",fill=TRUE) | ||
shhh <- suppressPackageStartupMessages # It's a library, so shhh! | ||
shhh(library(dplyr)) | ||
shhh(library(xfun)) | ||
shhh(library(dfeshiny)) | ||
|
||
error_flag <- FALSE | ||
|
||
datalog <- "datafiles_log.csv" | ||
log_files <- read.csv(datalog, stringsAsFactors = FALSE) | ||
ign_files <- read.csv(".gitignore", header = FALSE, stringsAsFactors = FALSE) | ||
colnames(ign_files)[1] <- "filename" | ||
|
||
cat("Contents of the .gitignore file:") | ||
print(ign_files) | ||
|
||
# Run a pass through the .gitignore files and look for any issues | ||
if(ncol(ign_files)>1){ | ||
cat("ERROR: It looks like you've got commas in the .gitignore. Please correct the .gitignore file and try again.") | ||
error_flag <- TRUE | ||
} else { | ||
for(i in 1:nrow(ign_files)){ | ||
if(grepl(' ',ign_files$filename[i])){ | ||
cat("ERROR: It looks like you've got spaces in filenames in the .gitignore. Please rename your files if they contain spaces and update the .gitignore file accordingly.") | ||
error_flag <- TRUE | ||
} | ||
} | ||
} | ||
|
||
suffixes <- "xlsx$|dat$|csv$|tex$|pdf$" | ||
|
||
current_files <- data.frame(files = list.files("./", recursive = TRUE)) %>% | ||
filter(grepl(suffixes, files), !grepl("renv|datafiles_log.csv", files)) | ||
|
||
for (file in current_files$files) { | ||
if (!file %in% log_files$filename) { | ||
cat("Error:", file, "is not recorded in datafiles_log.csv.\n\n") | ||
cat("Please add an entry to datafiles_log.csv for this file and mark it as unpublished, published or reference.\n\n") | ||
error_flag <- TRUE | ||
} else { | ||
file_status <- (log_files %>% filter(filename == file))$status | ||
if (!file_status %in% c("published", "Published", "reference", "Reference", "dummy", "Dummy")) { | ||
if (!file %in% ign_files$filename & !grepl("unpublished",file)) { | ||
cat("Error:", file, "is not logged as published or reference data in datafiles_log.csv and is not found in .gitignore.\n\n") | ||
cat("If the file contains published or reference data then update its entry in datafiles_log.csv.\n\n") | ||
cat("If the file contains unpublished data then add it to the .gitignore file.\n\n") | ||
error_flag <- TRUE | ||
} | ||
else { | ||
cat(file,"is recorded in the logfile as unpublished data and in .gitignore and so will not be included as part of the commit.\n\n") | ||
} | ||
} | ||
} | ||
} | ||
|
||
if(grepl('G-Z967JJVQQX', htmltools::includeHTML(("google-analytics.html"))) & | ||
!(toupper(Sys.getenv("USERNAME")) %in% c("CFOSTER4", "CRACE", "LSELBY","RBIELBY", "JMACHIN"))){ | ||
cat("Cleaning out the template's Google Analytics tag.",fill=TRUE) | ||
gsub_file("google-analytics.html", pattern = "G-Z967JJVQQX", replacement = "G-XXXXXXXXXX") | ||
gsub_file("ui.R", pattern = "Z967JJVQQX", replacement = "XXXXXXXXXX") | ||
system2(command = "git", args=c("add","google-analytics.html")) | ||
} | ||
|
||
if (error_flag) { | ||
cat("Warning, aborting commit. Unrecognised data files found, please update .gitignore or datafiles_log.csv.\n") | ||
quit(save = "no", status = 1, runLast = FALSE) | ||
} | ||
|
||
tidy_output <- tidy_code() | ||
if(any(tidy_output)){ | ||
error_flag <- TRUE | ||
} | ||
|
||
if (error_flag) { | ||
cat("Warning: Code did not appear to have been tidied.\nI've run tidy code for you, | ||
please check your files and the dashboard still works and then re-stage and try committing again.") | ||
quit(save = "no", status = 1, runLast = FALSE) | ||
} | ||
|
||
|
||
# End of hooks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
filename,status | ||
data/regional_data_FD_PG.csv,published | ||
data/regional_movement_FD_PG.csv,published | ||
data/sankey data 1-3YAG_FD_PG.csv,published | ||
data/sankey data 1-5YAG_FD_PG.csv,published | ||
data/sankey data 3-5YAG_FD_PG.csv,published | ||
data/tables_data_3digit_FD_PG.csv,published | ||
data/boundaries/Regions__December_2019__Boundaries_EN_BFE.cpg,published | ||
data/boundaries/Regions__December_2019__Boundaries_EN_BFE.dbf,published | ||
data/boundaries/Regions__December_2019__Boundaries_EN_BFE.prj,published | ||
data/boundaries/Regions__December_2019__Boundaries_EN_BFE.shp,published | ||
data/boundaries/Regions__December_2019__Boundaries_EN_BFE.shx,published |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.