Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gisma committed May 10, 2024
1 parent a852e20 commit 1ae43ea
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 79 deletions.
70 changes: 42 additions & 28 deletions R/initProj.R
Original file line number Diff line number Diff line change
Expand Up @@ -103,27 +103,28 @@ createFolders <- function(root_folder, folders,
#' @param code_subfolder subfolders for scripts and functions within the project directory that will be created. The
#' folders src and src/functions are mandatory.
#' @param global logical: export path strings as global variables?
#' @param libs vector with the names of libraries that are required for the initial project.
#' @param appendlibs vector with the names of libraries that are required for the initial project.
#' @param standard_setup use predefined settings. c("base","baseSpatial", "advancedSpatial"). In this case, only the name of the root folder is required.
#' @param openproject open project after creating it, d default = TRUE
#' @param newsession open project in a new session? default is FALSE
#' @param loc_name by default MySite defines the dataset folderlocation and is meant to be a code for the research site
#' @param ymlFN filename for a yaml file containing a non standard_setup
#' @param OpenFiles default NULL
#' @note For yaml based setup you need to use one of the default configurations
#' c("base", "baseSpatial","advancedSpatial") or you provide a yaml file this
#' MUST contain at least the standard_setup arguments where \code{ mysetup} is the yaml root\cr
#' MUST contain the standard_setup arguments, where \code{ mysetup} is the yaml root, all other items are mandatory keywords that can be filled in as needed.
#' \preformatted{
#'mysetup:
#' dataFolder:
#' docsFolder:
#' tmpFolder:
#' init_git: true/false
#' init_renv: true/false
#' code_subFolder: ["src", "src/functions" , "src/config"]
#' global: true/false
#' libs:
#' create_folders: true/false
#' files:
#' dataFolder:
#' docsFolder:
#' tmpFolder:
#' init_git: true/false
#' init_renv: true/false
#' code_subfolder: ["src", "src/functions" , "src/config"]
#' global: true/false
#' libs:
#' create_folders: true/false
#' files:
#'}
#' Alternatively you may set default_setup to NULL and provide the arguments via command line.
#' @details The function uses [setupProj] for setting up the folders. Once the project is creaeted, manage the overall
Expand All @@ -148,10 +149,14 @@ createFolders <- function(root_folder, folders,
#'
initProj <- function(root_folder = ".", folders = NULL, folder_names = NULL,
init_git = NULL, init_renv = NULL, code_subfolder = c("src", "src/functions"),
global = FALSE, libs = NULL, openproject = NULL, newsession=NULL,
standard_setup = "baseSpatial",loc_name = NULL, ymlFN = NULL ) {

global = FALSE, openproject = NULL,
standard_setup = "baseSpatial",loc_name = NULL, ymlFN = NULL ,appendlibs = NULL, OpenFiles = NULL) {


notes = TRUE
if (loc_name == "") loc_name = NULL
if (is.null(appendlibs)) appendlibs = "dplyr"
if (is.null(openproject)) openproject = FALSE
# Setup project directory structure
if (standard_setup %in% c("base", "baseSpatial","advancedSpatial"))
{
Expand All @@ -160,13 +165,13 @@ initProj <- function(root_folder = ".", folders = NULL, folder_names = NULL,
envrmt = read_yaml(file = ymlFN)
}

if (is.null(libs)){
if (is.null(appendlibs)){
libs = envrmt$libs
} else {
libs = append(libs,envrmt$libs)
libs = append(appendlibs,envrmt$libs)
}
appendlibs = ""
if (!is.null(libs)){

if (!is.null(code_subfolder) | length(code_subfolder) > 0){
code_subfolder = unique(append(code_subfolder,envrmt$code_subfolder))
} else {
code_subfolder = envrmt$code_subfolder
Expand Down Expand Up @@ -201,20 +206,22 @@ initProj <- function(root_folder = ".", folders = NULL, folder_names = NULL,
standard_setup = NULL
)
}


# create R project and scripts
brew::brew(system.file(sprintf("templates/%s.brew", "rstudio_proj"), package = "link2GI"), file.path(root_folder, paste0(basename(root_folder), ".Rproj")))
brew::brew(system.file(sprintf("templates/%s.brew", "script_control"), package = "link2GI"), file.path(dirs$src, "main-control.R"))
brew::brew(system.file(sprintf("templates/%s.brew", "pre-processing"), package = "link2GI"), file.path(dirs$src, "preprocessing.R"))
brew::brew(system.file(sprintf("templates/%s.brew", "pre-processing"), package = "link2GI"), file.path(dirs$src, "pre-processing.R"))
brew::brew(system.file(sprintf("templates/%s.brew", "processing"), package = "link2GI"), file.path(dirs$src, "10-processing.R"))
brew::brew(system.file(sprintf("templates/%s.brew", "post-processing"), package = "link2GI"), file.path(dirs$src, "postprocessing.R"))
brew::brew(system.file(sprintf("templates/%s.brew", "config-master"), package = "link2GI"), file.path(dirs$src, "config-master-yml"))
brew::brew(system.file(sprintf("templates/%s.brew", "post-processing"), package = "link2GI"), file.path(dirs$src, "post-processing.R"))
brew::brew(system.file(sprintf("templates/%s.brew", "config-master-yml"), package = "link2GI"), file.path(dirs$src, "config-master-yml"))
brew::brew(system.file(sprintf("templates/%s.brew", standard_setup), package = "link2GI"),file.path(dirs$functions, "000_setup.R"))
brew::brew(system.file(sprintf("templates/%s.brew", "yml"), package = "link2GI"),file.path(dirs$configs, "pre-processing.yml"))
brew::brew(system.file(sprintf("templates/%s.brew", "yml"), package = "link2GI"),file.path(dirs$configs, "processing.yml"))
brew::brew(system.file(sprintf("templates/%s.brew", "yml"), package = "link2GI"),file.path(dirs$configs, "post-processing.yml"))
createScript(new_file = file.path(root_folder, "README.md"), template = "readme", notes = TRUE)
brew::brew(system.file(sprintf("templates/%s.brew", "yml"), package = "link2GI"),file.path(dirs$config, "pre-processing.yml"))
brew::brew(system.file(sprintf("templates/%s.brew", "yml"), package = "link2GI"),file.path(dirs$config, "processing.yml"))
brew::brew(system.file(sprintf("templates/%s.brew", "yml"), package = "link2GI"),file.path(dirs$config, "post-processing.yml"))
brew::brew(system.file(sprintf("templates/%s.brew", "readme"), package = "link2GI"),file.path(dirs$config, "README.md"))



# Init git
# if (use_standard_setup) init_git <- setup_default()[[standard_setup[1]]]$init_git
Expand All @@ -232,7 +239,14 @@ initProj <- function(root_folder = ".", folders = NULL, folder_names = NULL,
#yaml::write_yaml(dirs,file = file.path("pPath.yaml"))
#dirs = createFolders(root_folder = here::here(root_folder),folders = dirs,create_folders = FALSE)
# yaml::write_yaml(dirs,file.path(here::here(root_folder),"src/functions/dirs.yaml"))
if (openproject) rstudioapi::openProject(file.path(root_folder, paste0(basename(root_folder), ".Rproj")),newSession = newsession)
# if (is.null(OpenFiles)) {
# rstudioapi::navigateToFile("src/pre-processing.R")
# rstudioapi::navigateToFile("src/post-processing.R")
# rstudioapi::navigateToFile("src/10-processing.R")
# rstudioapi::navigateToFile("src/functions/000_setup.R")
# rstudioapi::navigateToFile("src/main-control.R")
# }
#if (openproject) rstudioapi::openProject(file.path(root_folder, paste0(basename(root_folder), ".Rproj")),newSession = newsession)
return(dirs)
}

Expand Down
2 changes: 1 addition & 1 deletion docs/pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ articles:
link2GI5: link2GI5.html
link2GI6: link2GI6.html
link2GI7: link2GI7.html
last_built: 2024-05-10T07:23Z
last_built: 2024-05-10T11:54Z
urls:
reference: https://r-spatial.github.io/link2GI/reference
article: https://r-spatial.github.io/link2GI/articles
Expand Down
48 changes: 26 additions & 22 deletions docs/reference/initProj.html

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

8 changes: 5 additions & 3 deletions inst/rstudio/templates/project/initProj.dcf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Binding: initProj
Title: Create Project structure (link2GI)
OpenFiles: README.md, src/main.R, src/functions/000_setup.R
OpenFiles: src/pre-processing.R, src/post-processing.R, src/10-processing.R , src/functions/000_setup.R , src/main-control.R

Parameter: init_git
Widget: CheckboxInput
Expand All @@ -18,14 +18,16 @@ Label: configuration
Fields: base, baseSpatial,advancedSpatial
Position: left

Parameter: libs
Parameter: appendlibs
Widget: TextInput
Label: load libraries
Default:
Default: dplyr
Position: right

Parameter: loc_name
Widget: TextInput
Label: location tag
Default:
Position: right


10 changes: 5 additions & 5 deletions inst/templates/config-default-projects.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ base:
tmpFolder: ["tmp"]
init_git: true
init_renv: true
code_subFolder: ["src", "src/functions" , "src/config"]
code_subfolder: ["src", "src/functions" , "src/config"]
global: false
libs: ""
create_folders: true
files: ["main.R", "000-setup.R", "README.qmd"]
files: [ "pre-processing.R", "post-processing.R", "10-processing.R", "src/functions/000_setup.R" ,"src/main-control.R"]
baseSpatial:
dataFolder: ["level0", "level1", "level2", "run" ,"aux"]
docsFolder: [ "figures"]
Expand All @@ -19,7 +19,7 @@ baseSpatial:
global: false
libs: ["terra", "stars", "sf" , "RStoolbox", "tmap" , "mapview", "dplyr"]
create_folders: true
files: ["main.R", "000-setup.R", "README.qmd"]
files: [ "pre-processing.R", "post-processing.R", "10-processing.R", "src/functions/000_setup.R" ,"src/main-control.R"]
advancedSpatial:
dataFolder: ["level0", "level1", "level2", "run"]
docsFolder: [ "figures"]
Expand All @@ -30,7 +30,7 @@ advancedSpatial:
global: false
libs: ["terra", "stars", "sf" , "RStoolbox", "tmap" , "mapview" ,"dplyr", "caret" ,"randomforest"]
create_folders: true
files: ["main.R", "000-setup.R", "README.qmd"]
files: [ "pre-processing.R", "post-processing.R", "10-processing.R", "src/functions/000_setup.R" ,"src/main-control.R"]



1 change: 0 additions & 1 deletion inst/templates/script_setup.brew
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
require(link2GI)

# Define libraries
libs <- appendlibs

# Load libraries and create environment object to be used in other scripts for path navigation
project_folders <- list.dirs(path = root_folder, full.names = FALSE, recursive = TRUE)
Expand Down
2 changes: 1 addition & 1 deletion inst/templates/yml.brew
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ filenames:

tags:

parameter:
parameter:
38 changes: 20 additions & 18 deletions man/initProj.Rd

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

0 comments on commit 1ae43ea

Please sign in to comment.