diff --git a/.Rbuildignore b/.Rbuildignore
index 85a907a..70f2dd5 100644
--- a/.Rbuildignore
+++ b/.Rbuildignore
@@ -1,3 +1,5 @@
+^renv$
+^renv\.lock$
^.*\.Rproj$
^\.Rproj\.user$
^ReadMe.md
@@ -11,3 +13,6 @@ hex_sticker.R
^_pkgdown\.yml$
^docs$
^pkgdown$
+^vignettes/sas-macros.Rmd
+^altdoc$
+^_quarto$
diff --git a/.github/workflows/R-Build-Test_cleanupBranch.yml b/.github/workflows/R-Build-Test_cleanupBranch.yml
index 38cd358..5cec1e0 100644
--- a/.github/workflows/R-Build-Test_cleanupBranch.yml
+++ b/.github/workflows/R-Build-Test_cleanupBranch.yml
@@ -10,7 +10,7 @@ name: R
on:
push:
- branches: [] #branches: [ "cleanup_edits_SM" ]
+ branches: [ "cleanup_edits_SM" ]
permissions:
contents: read
@@ -22,8 +22,12 @@ jobs:
fail-fast: true
matrix:
r-version: ['release']
- os: [ubuntu-latest, windows-latest, macos-latest]
+ os: [ubuntu-latest, windows-latest, macos-latest] #[ubuntu-latest]
+ env:
+ GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
+ permissions:
+ contents: write
steps:
- uses: actions/checkout@v4
@@ -33,10 +37,22 @@ jobs:
r-version: ${{ matrix.r-version }}
use-public-rspm: true
+ - name: Cache R
+ uses: actions/cache@v4
+ with:
+ path: ${{ env.R_LIBS_USER }}
+ key: ${{ runner.os }}-r-${{ matrix.r-version }}-${{ hashFiles('DESCRIPTION') }}-${{ hashFiles('**/renv.lock') }}
+ restore-keys: |
+ ${{ runner.os }}-r-${{ matrix.r-version }}-${{ hashFiles('**/renv.lock') }}
+ ${{ runner.os }}-r-${{ matrix.r-version }}
+
+
+
- name: Install dependencies
+ if: steps.cache-r.outputs.cache-hit != 'true'
uses: r-lib/actions/setup-r-dependencies@v2
with:
- extra-packages: any::rcmdcheck
+ extra-packages: any::rcmdcheck,altdoc,quarto,roxygen2,remotes
needs: check
- name: Check Package
@@ -44,4 +60,20 @@ jobs:
with:
upload-snapshots: true
build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")'
+ error-on: '"error"'
+
+ - name: Show testthat output
+ if: always()
+ run: |
+ ## --------------------------------------------------------------------
+ find '${{ runner.temp }}/package' -name 'testthat.Rout*' -exec cat '{}' \; || true
+ shell: bash
+
+ - name: Upload test results
+ if: failure()
+ uses: actions/upload-artifact@v4
+ with:
+ name: coverage-test-failures
+ path: ${{ runner.temp }}/package
+
diff --git a/.github/workflows/altdoc_quarto.yaml b/.github/workflows/altdoc_quarto.yaml
new file mode 100644
index 0000000..8090f53
--- /dev/null
+++ b/.github/workflows/altdoc_quarto.yaml
@@ -0,0 +1,65 @@
+# Workflow derived from https://github.com/CIDA-CSPH/CIDAtools/pkgdown.yaml
+
+on:
+ push:
+ branches: [main, master]
+ pull_request:
+ branches: [main, master]
+ release:
+ types: [published]
+ workflow_dispatch:
+
+name: altdoc_quarto_site
+
+jobs:
+ build_doc:
+ runs-on: ubuntu-latest
+ strategy:
+ fail-fast: true
+ matrix:
+ r-version: ['release']
+ # Only restrict concurrency for non-PR jobs
+ env:
+ GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
+ permissions:
+ contents: write
+ steps:
+ - uses: actions/checkout@v4
+
+ - uses: r-lib/actions/setup-pandoc@v2
+
+ - name: Set up R ${{ matrix.r-version }}
+ uses: r-lib/actions/setup-r@v2
+ with:
+ r-version: ${{ matrix.r-version }}
+ use-public-rspm: true
+
+ - name: Install dependencies
+ uses: r-lib/actions/setup-r-dependencies@v2
+ with:
+ extra-packages: local::.,any::rcmdcheck,any::altdoc,any::quarto,any::roxygen2
+ needs: check
+
+ - name: Cache R
+ uses: actions/cache@v4
+ with:
+ path: ${{ env.R_LIBS_USER }}
+ key: ${{ runner.os }}-r-${{ hashFiles('DESCRIPTION') }}
+
+ - uses: r-lib/actions/check-r-package@v2
+ with:
+ upload-snapshots: true
+
+ - name: Run Roxygen2
+ run: Rscript -e 'roxygen2::roxygenise()'
+
+ - name: Build Altdoc Site
+ run: Rscript -e 'altdoc::render_docs(path = ".", verbose = FALSE, parallel = FALSE, freeze = FALSE)'
+
+ - name: Deploy to GitHub pages 🚀
+ if: github.event_name != 'pull_request'
+ uses: JamesIves/github-pages-deploy-action@v4.4.1
+ with:
+ clean: false
+ branch: gh-pages
+ folder: docs
diff --git a/.github/workflows/pkgdown.yaml b/.github/workflows/pkgdown.yaml
deleted file mode 100644
index ed7650c..0000000
--- a/.github/workflows/pkgdown.yaml
+++ /dev/null
@@ -1,48 +0,0 @@
-# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
-# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
-on:
- push:
- branches: [main, master]
- pull_request:
- branches: [main, master]
- release:
- types: [published]
- workflow_dispatch:
-
-name: pkgdown
-
-jobs:
- pkgdown:
- runs-on: ubuntu-latest
- # Only restrict concurrency for non-PR jobs
- concurrency:
- group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }}
- env:
- GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
- permissions:
- contents: write
- steps:
- - uses: actions/checkout@v3
-
- - uses: r-lib/actions/setup-pandoc@v2
-
- - uses: r-lib/actions/setup-r@v2
- with:
- use-public-rspm: true
-
- - uses: r-lib/actions/setup-r-dependencies@v2
- with:
- extra-packages: any::pkgdown, local::.
- needs: website
-
- - name: Build site
- run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE)
- shell: Rscript {0}
-
- - name: Deploy to GitHub pages 🚀
- if: github.event_name != 'pull_request'
- uses: JamesIves/github-pages-deploy-action@v4.4.1
- with:
- clean: false
- branch: gh-pages
- folder: docs
diff --git a/.gitignore b/.gitignore
index 3c84d79..0290339 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,3 +7,10 @@
inst/doc
*.DS_Store
docs
+/tests/testthat/*.rds
+
+
+/.quarto/
+altdoc/freeze.rds
+_quarto/*
+!_quarto/_freeze/
diff --git a/DESCRIPTION b/DESCRIPTION
index 1069bfe..e8e0227 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -1,26 +1,28 @@
Package: CIDAtools
Title: This package contains tools for CIDA projects
-Version: 0.1.2
+Version: 0.2.0
Authors@R:
- c(person("CIDA Research Tools Committee", role = c("aut", "cre"), email = "ryan.a.peterson@cuanschutz.edu"))
+ c(person("CIDA Research Tools Committee", role = c("aut", "cre"), email = "CIDA-RT@olucdenver.onmicrosoft.com"))
Description: This package contains the numerous templates and tools to make life at CIDA (part of the Colorado School of Public Health) happier and more efficient!
-Depends: R (>= 3.5.0)
+Depends: R (>= 4.0)
Imports:
dplyr,
generics,
flextable,
table1,
- shiny
+ shiny,
+ fs
Suggests:
- git2r,
- survey,
- xlsx,
+ git2r,
+ survey,
+ quarto,
+ xlsx,
knitr,
- pander,
+ pander,
arsenal,
rmarkdown,
DT,
- covr,
+ covr,
shinythemes,
stats,
Hmisc,
@@ -30,9 +32,11 @@ Suggests:
tableone,
cardx,
stats,
- broom.helpers
+ broom.helpers,
+ testthat (>= 3.0.0)
+Config/testthat/edition: 3
License: CC0
Encoding: UTF-8
-RoxygenNote: 7.3.2
-VignetteBuilder: knitr
+RoxygenNote: 7.3.3
+VignetteBuilder: quarto, knitr
URL: https://cida-csph.github.io/CIDAtools/
diff --git a/NAMESPACE b/NAMESPACE
index 012de44..c39a0c7 100644
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -18,14 +18,40 @@ export(convertIntervalNotation)
export(create_project)
export(find_nearest)
export(getProjectData)
+export(get_default_value)
+export(get_defaults)
+export(get_full_project_path)
+export(get_global_default_analyst)
+export(get_global_default_path)
+export(get_project_analyst)
+export(get_project_drive_path)
+export(get_project_github)
+export(get_project_location)
+export(get_project_meta_data)
+export(get_project_name)
+export(get_project_pi)
export(list_kables)
export(nLevelsP)
export(nrowP)
+export(open_project)
export(pvalr)
export(randblinder_shiny_tool)
export(read_xlsx_color)
export(removeAnalyst)
+export(remove_global_default_analyst)
+export(remove_global_default_path)
export(setAnalyst)
+export(setPermanentAnalyst)
+export(set_default_value)
+export(set_full_project_path)
+export(set_global_default_analyst)
+export(set_global_default_path)
+export(set_project_analyst)
+export(set_project_github)
+export(set_project_location)
+export(set_project_meta_data)
+export(set_project_name)
+export(set_project_pi)
export(sum_ignore_NA)
export(vec_power)
import(flextable)
@@ -41,3 +67,4 @@ importFrom(stats,wilcox.test)
importFrom(table1,stats.apply.rounding)
importFrom(table1,stats.default)
importFrom(table1,table1)
+importFrom(utils,head)
diff --git a/NEWS.md b/NEWS.qmd
similarity index 68%
rename from NEWS.md
rename to NEWS.qmd
index ba3b7b5..0cd882b 100644
--- a/NEWS.md
+++ b/NEWS.qmd
@@ -1,3 +1,11 @@
+---
+title: "CIDATools - News"
+format: html
+---
+# 0.2.0
+- Refactored most functions to use consistent camelCase naming conventions
+- Deprecated some unused/unsupported functions (if you encounter a deprecated function which you are actively using, please email CIDA-RT@olucdenver.onmicrosoft.com)
+
# 0.1.1
- Data only argument implemented
diff --git a/R/backup_project.R b/R/backup_project.R
deleted file mode 100644
index 1c512f1..0000000
--- a/R/backup_project.R
+++ /dev/null
@@ -1,176 +0,0 @@
-#'Backup Project Directory
-#'
-#'This function backs up a CIDA project to the shared (P) CIDA drive. The backup directory
-#'can either be existing (in which only changed files/folders are updated), or
-#'nonexisting, in which case a full project backup is created.
-#'
-#'@param path_from Path from where the folders should be copied (project
-#' directory location).
-#'@param path_to Path to where the folders should be copied (P drive, only used
-#' if specified).
-#'@param exclude files/folders NOT to be backed up to the P-drive (useful for
-#'larger files that don't change often). Currently not used.
-#'@param recreate should backup be created from the ground up?
-#' (can take longer, but useful for projects with many changes)
-#' @param data_only should only subdirs including "data" (DataRaw/ and DataProcessed/) be backed up?
-#' @param readme forces backup of project readme
-#' @return This function has verbose output to ensure the back up is working, and
-#' ultimately returns a success indicator that's returned by file.copy.
-#'
-#'@export
-backup_project <- function(path_from = getwd(),
- path_to = NULL,
- exclude = c(".DS_Store", ".Rproj.user", ".git"),
- recreate = FALSE,
- data_only = TRUE,
- readme = TRUE) {
-
- # Check args, make into absolute paths
- path_from <- normalizePath(path_from)
-
- # Get proper path to Shared drive
- if(missing(path_to)) {
-
- path_to <- ProjectLocation()
- if(path_to == "")
- stop("Please first set project location, e.g., CIDAtools::SetProjectLocation('Branches/EmergencyMedicine/ThisProject')")
-
- if(!dir.exists(CIDAtools::CIDA_drive_path()))
- stop("Please ensure the CIDA drive is mounted, or set `path_to`")
-
- }
-
- path_to <- normalizePath(path_to)
-
- ## Check if specific project folder exists on P drive
- backup_path <- file.path(path_to)
- if(!dir.exists(backup_path)) {
- message("Note: '", backup_path, "' not found; directory was created.")
- dir.create(backup_path)
- } else if (!recreate){
- message("Note: backup path already exists, and will be updated unless cancelled.")
- message("Backup path:\n", backup_path,
- "\nProject path:\n",
- path_from)
- } else {
- message("Note: backup path already exists, and will be completely overwritten since recreate == TRUE.")
- message("Backup path:\n", backup_path,
- "\nProject path:\n",
- path_from, "\n\nType 'yes' to confirm.")
- delete_old <- readline()
-
- if(delete_old != "yes")
- stop("Cancelled")
- unlink(backup_path, recursive=TRUE)
- dir.create(backup_path)
- }
-
- message("\nDetermining current backup situation...")
-
- files_to_copy <-
- list.files(path_from, recursive = T, all.files = T)
- dirs_to_copy <- list.dirs(path_from, recursive = T, full.names = F)[-1]
-
- if(length(exclude)) {
- files_to_exclude <- c(
- unlist(sapply(exclude[dir.exists(exclude)], list.files, recursive = TRUE,
- all = TRUE, full.names = T)),
- exclude[!dir.exists(exclude)])
-
- files_to_copy <- files_to_copy[!(files_to_copy %in% files_to_exclude)]
-
- dirs_to_exclude <- c(
- unlist(sapply(exclude[dir.exists(exclude)], list.dirs, recursive = TRUE,
- full.names = T)))
-
- dirs_to_copy <- dirs_to_copy[!(dirs_to_copy %in% dirs_to_exclude)]
- }
-
- if(data_only) {
- string_matches <- "dataraw|dataprocessed"
- if(readme)
- string_matches <- "readme|dataraw|dataprocessed"
-
- # find large files (>= 250 MB)
- large_idx <- file.size(files_to_copy)/1e6 >= 250
-
- # find file matches
- file_matches <- grepl(string_matches, files_to_copy, ignore.case = TRUE)
- dir_matches <- grepl(string_matches, dirs_to_copy, ignore.case = TRUE)
-
- files_to_copy <- files_to_copy[large_idx | file_matches]
- dirs_to_copy <- dirs_to_copy[large_idx | dir_matches]
- }
-
- ## Check if any files can be ignored using time last modified time
- check <- file.exists(file.path(backup_path, files_to_copy))
- if(any(check)) {
- to_mtime <- file.mtime(file.path(backup_path, files_to_copy))
-
- # If no file found, set last modified time into future (kind of a hack)
- to_mtime[is.na(to_mtime)] <- Sys.time() +500
-
- from_mtime <- file.mtime(file.path(path_from, files_to_copy))
- files_to_copy <- files_to_copy[abs(difftime(to_mtime, from_mtime, units = "secs")) > 1]
- }
-
- # Check and don't copy dirs if they already exist
- dirs_to_copy <- dirs_to_copy[!dir.exists(file.path(backup_path, dirs_to_copy))]
-
- message("\nI'm about to create or update ",length(dirs_to_copy)," subdirectories and ",
- length(files_to_copy), " files.",
- "'\nType 'yes' to confirm, or 'list' to list changes.")
- val <- readline()
- if(val == "list") {
- cat("Subdirs:", dirs_to_copy, sep = "\n")
- cat("\n\nFiles:", files_to_copy, sep = "\n")
- message("'\n\n Type 'yes' to confirm.")
- val <- readline()
- }
-
- stopifnot(val == "yes")
-
- if(length(dirs_to_copy)) {
- message("Creating ", length(dirs_to_copy)," subdirectories...")
- pb <- dplyr::progress_estimated(length(dirs_to_copy))
- r1 <- sapply(1:length(dirs_to_copy), function(i) {
- pb$tick()$print()
- dir.create(file.path(backup_path, dirs_to_copy[i]))
- })
- } else
- r1 <- T
-
- if(length(files_to_copy)) {
- message("\nCopying/updating ", length(files_to_copy), " files...")
- pb <- dplyr::progress_estimated(length(files_to_copy))
- r2 <- sapply(1:length(files_to_copy), function(i) {
- pb$tick()$print()
- file.copy(file.path(path_from, files_to_copy[i]),
- file.path(backup_path, files_to_copy[i]),
- overwrite = TRUE, copy.date = TRUE)
-
- })
- } else
- r2 <- T
-
- result <- all(r1) & all(r2)
- create_backup_info(backup_path)
-
- return(invisible(result))
-}
-
-create_backup_info <- function(path) {
- fileConn<- file(file.path(path, "backup_info.md"))
- lines <- c(
- "This is a backup of the actual project directory. ",
- "",
- "DO NOT EDIT THIS DIRECTORY.",
- "",
- "If you do, changes may be overwritten by future backups.",
- "",
- paste0("This directory was last backed up at ", Sys.time()),
- ""
- )
- writeLines(lines, fileConn)
- close(fileConn)
-}
diff --git a/R/cida_drive_path.R b/R/cida_drive_path.R
deleted file mode 100644
index fc468e4..0000000
--- a/R/cida_drive_path.R
+++ /dev/null
@@ -1,71 +0,0 @@
-#' Get CIDA drive path
-#'
-#' This function attempts to get the proper path for the CIDA drive either on
-#' Windows or Mac.
-#'
-#' @param file (optional) Path to subdirectory/file within CIDA drive
-#'
-#' @return Full (absolute) file path of CIDA drive
-#' @export
-#'
-#' @examples
-#' # Read data from P1234PIname project
-#' \dontrun{
-#' df <- read.csv(CIDA_drive_path("BRANCHES/Pulmonary/P1234PIname/DataRaw/data.csv"))
-#' }
-#'
-
-CIDA_drive_path <- function(file = "") {
-
- # Get operating system (note that MacOS and Linux return unix)
- os <- .Platform$OS.type
-
- if (os == "unix") { # MacOS/Linux
-
- # Two potential places drive could exist
- if (dir.exists("/Volumes/sph-cida")) {
- path <- "/Volumes/sph-cida"
- } else {
- stop("Nothing found at /Volumes/sph-cida.",
- " Please ensure drive is mounted and you have entered your",
- " password to access the drive (and are logged into the VPN if",
- " needed.)")
- }
-
- } else if (os == "windows") { # Windows
-
- # Only one spot drive can be mounted for Windows
- if (dir.exists("P:/")) {
- path <- "P:/"
- } else {
- stop("Nothing found at P:/.",
- " Please ensure drive is mounted and you have entered your",
- " password to access the drive (and are logged into the VPN if",
- " needed.)")
- }
-
-
- } else {
-
- stop("Operating system could not be identified")
-
- }
-
- # Combine CIDA drive path with user provided subdirectory/file
- file_path <- file.path(path, file)
-
- # Check if full path exists (first as file, second as directory)
- if (!dir.exists(file_path) & !file.exists(file_path)) {
-
- # TODO: consider adding function to search for partial paths and suggest
- # alternatives
-
- stop("Nothing found at path ", file_path,
- "\nCheck spelling of path, and ensure drive is mounted and you have",
- " entered your password to access the drive (and are logged into the",
- " VPN if needed.)")
- }
-
- # Return full path
- return(file_path)
-}
diff --git a/R/cida_table1.R b/R/cida_table1.R
index c99678b..e9b30c6 100644
--- a/R/cida_table1.R
+++ b/R/cida_table1.R
@@ -1,4 +1,4 @@
-#' Create a table one
+#' Create a table one - To be deprecated
#'
#'
#' This is a function created to provide characteristics of a study group with
@@ -155,6 +155,8 @@ cida_table1 <- function(data,
useSciNotation = FALSE
) {
+ deprecation_warn("cida_table1.cida_table1")
+
# Check variables are in provided data
if (any(!(includeVars %in% colnames(data))) &
if (!is.null(names(includeVars))) {
@@ -493,7 +495,7 @@ cida_table1 <- function(data,
}
}
-#' Internal function for p-value calculation in cida_table1
+#' Internal function for p-value calculation in cida_table1 - To be deprecated
#'
#' @param x the row_variable
#' @param name the variables name
@@ -512,6 +514,7 @@ pvalue <- function(x,
include_total = include_total,
nonParametricVars = nonParametricVars) {
+ deprecation_warn("cida_table1.pvalue")
# Construct vectors of data y, and groups (strata) g
if (isTRUE(include_total)) {
diff --git a/R/create_project.R b/R/create_project.R
deleted file mode 100644
index 17342cc..0000000
--- a/R/create_project.R
+++ /dev/null
@@ -1,284 +0,0 @@
-#'Create Project Directory + readme files
-#'
-#'This function creates the standard project organization structure for CIDA
-#'within a folder that already exists.
-#'
-#'@param path Where should they be created? Default is the working directory.
-#'@param template Which subdirectories to create
-#'@param ProjectName Name of project, or "" for blank
-#'@param PI Name of PI and credentials, or "" for blank
-#'@param analyst Name of Analyst(s), or "" for blank
-#'@param datalocation Location of project on CIDA Drive, or "" for blank
-#'@param gitlocation Location project on GitHub
-#'@return This function creates the desired project subdirectories and readmes,
-#' as well as a standard .gitignore file files. It will not overwrite the file
-#' however if it does not exist. It does not return anything.
-#'@keywords project createproject
-#'
-#'@seealso proj_setup() is the internal wrapper for this that gets called when
-#' using the RStudio GUI to create a project
-#'
-#'@export
-create_project <- function(path = getwd(),
- template = c('Admin', 'Background', 'Code', 'DataRaw',
- 'DataProcessed', 'Dissemination', 'Reports'),
- ProjectName = "", PI = "", analyst = "", datalocation = "",
- gitlocation = "") {
-
- if(!dir.exists(path))
- dir.create(path, recursive = TRUE, showWarnings = FALSE)
-
- # has meta been provided?
- meta <- !all(c(ProjectName, PI, analyst, datalocation) %in% "")
-
- # set which ReadMe.md files to create
- template <- match.arg(template, several.ok = T)
-
- # Overall readme
-
- readme <- c(paste0("**Project Name**: ", ProjectName, " "),
- paste0("**PI**: ", PI, " "),
- paste0("**Analyst**: ", analyst, " "),
- paste0("**CIDA drive Location**: ", proj.location.handler(datalocation), " "),
- paste0("**GitHub Location**: ", gitlocation, " "),
- "",
- "Details about the folders:",
- '',
- "File | Description",
- "---|----------------------------------------------------------",
- paste("Admin | contains the scope of work and other",
- "administrative documents"),
- paste("Background | contains the background information for",
- "the analysis"),
- "Code | contains all R scripts for this project",
- "DataRaw | contain all raw data provided by investigators",
- "DataProcessed | contains the processed data used for analysis",
- paste("Dissemination | contains any materials produced for",
- "dissemination, ie. Abstracts, Posters, Papers"),
- "Reports | contains all output, rmarkdown files and report")
-
-
- # write to readme file
- if(!file.exists(file.path(path, "ReadMe.md")))
- writeLines(paste0(readme, collapse = '\n'),
- con = file.path(path, "ReadMe.md"))
-
- # Create subdirectory readmes
- create_readme(template = template, path = path)
-
- # Add .ProjData directory containing metadata
- if(meta){
- dir.create(paste0(path, '/.ProjData'))
- ProjData <- list(ProjectName = ProjectName, PI = PI,
- analyst = analyst, datalocation = datalocation,
- gitlocation = gitlocation)
- write.dcf(ProjData, file.path(path, '/.ProjData/Data.dcf'))
- }
-
- # add to current gitignore if exists
- if(file.exists(file.path(path, '.gitignore'))){
- gitignore <- readLines(con = file.path(path, '.gitignore'))
- } else {
- gitignore <- NULL
- }
-
- # add R template gitignore
- # (source: https://github.com/github/gitignore/blob/master/R.gitignore)
- gitignore <- paste0(c(gitignore,
- "# History files",
- ".Rhistory",
- ".Rapp.history",
-
- "# Session Data files",
- ".RData",
-
- "# User-specific files",
- ".Ruserdata",
-
- "# Example code in package build process",
- "*-Ex.R",
-
- "# Output files from R CMD build",
- "/*.tar.gz",
-
- "# Output files from R CMD check",
- "/*.Rcheck/",
-
- "# RStudio files",
- ".Rproj.user/",
-
- "# produced vignettes",
- "vignettes/*.html",
- "vignettes/*.pdf",
-
- paste0("# OAuth2 token, see https://github.com/",
- "hadley/httr/releases/tag/v0.3"),
- ".httr-oauth",
-
- "# knitr and R markdown default cache directories",
- "/*_cache/",
- "/cache/",
-
- "# Temporary files created by R markdown",
- "*.utf8.md",
- "*.knit.md"), collapse = '\n')
-
- # by file type
- gitignore <- paste0(c(gitignore,
- "# R Data files",
- "*.RData",
- "*.rda",
- "*.rdata",
- "*.rda",
- "# Text files",
- "*.csv",
- "*.txt",
- "*.dat",
- "# Excel",
- "*.xls*",
- "# SAS",
- "*.sas7bdat",
- "*.xport",
- "# Access",
- "*.mdb"), collapse = '\n')
-
- # by Folder
- gitignore <- paste0(c(gitignore,
- "DataRaw/*",
- "DataProcessed/*",
- "!*/ReadMe.md"), collapse = '\n')
-
- writeLines(gitignore, con = file.path(path, '.gitignore'))
-
- # Create .Rproj file
- rproj <- paste0(c("Version: 1.0",
- "",
- "RestoreWorkspace: Default",
- "SaveWorkspace: Default",
- "AlwaysSaveHistory: Default",
- "",
- "EnableCodeIndexing: Yes",
- "UseSpacesForTab: Yes",
- "NumSpacesForTab: 2",
- "Encoding: UTF-8",
- "",
- "RnwWeave: knitr",
- "LaTeX: pdfLaTeX"), collapse = "\n")
-
- if(!file.exists(file.path(path, paste0(basename(path), ".Rproj"))))
- writeLines(rproj, con = file.path(path, paste0(basename(path), ".Rproj")))
-
- ## Copy over SOW
- message("Project created. Please remember to copy the scope of work to to Admin/ subdirectory.")
-
- invisible(template)
-}
-
-proj_setup <- function(path, ...){
- # ensure path exists
- dots <- list(...)
- ProjectName <- paste0(path)
-
- create_project(path, ProjectName = paste0(path), PI = dots$PI,
- analyst = dots$analyst, datalocation = dots$datalocation,
- gitlocation = dots$gitlocation)
-
- # for project info
- dir.create(paste0(path, '/.ProjData'))
- ProjData <- list(ProjectName = ProjectName, PI = dots$PI,
- analyst = dots$analyst, datalocation = dots$datalocation,
- gitlocation = dots$gitlocation)
- write.dcf(ProjData, file.path(path, '/.ProjData/Data.dcf'))
-
-}
-
-create_readme <- function(template = c('Admin', 'Background', 'Code', 'DataRaw',
- 'DataProcessed', 'Dissemination',
- 'Reports'), path = getwd()){
- # set which ReadMe.md files to create
- template <- match.arg(template, several.ok = T)
-
- # create list with lines for each template
- readme <- list()
-
- readme$Admin <- c("# Admin ",
- " ",
- "This folder contains the scope of work and other relevant files from CIDA admin. ",
- " ",
- "Details about the files: ",
- " ",
- "File | Description",
- "---|---------------------------------------------------------------------",
- " ",
- "")
- readme$Background <- c("# Background ",
- " ",
- "This folder contains documents provided by investigators and the data analysis plan. ",
- " ",
- "Details about the files: ",
- " ",
- "File | Description",
- "---|---------------------------------------------------------------------",
- " ")
- readme$Code <- c("This folder contains all the code. ",
- " ",
- "Details about the files in this folder:",
- " ",
- "File | Description",
- "---|---------------------------------------------------------------------",
- " ")
- readme$DataProcessed <- c("# Processed Data ",
- " ",
- "Scripts that created the files in this folder: ",
- " ",
- "File | Script | Description",
- "---|------------------|---------------------------------------------------",
- " ")
- readme$DataRaw <- c("# Raw Data",
- " ",
- "Details about the files: ",
- " ",
- "File | Details",
- "---|---------------------------------------------------------------------",
- " ",
- " ")
-
- readme$Dissemination <- c("# Dissemination",
- " ",
- "This folder contains abstracts, posters, papers and anything else produced for dissemination. ",
- " ",
- "Details about the files: ",
- " ",
- "File | Description",
- "---|---------------------------------------------------------------------",
- " ",
- " ")
- readme$Reports <- c("# Reports",
- " ",
- "This folder contains the rmarkdown scripts and pdf output of reports. ",
- " ",
- "Details about the files: ",
- " ",
- "File | Description",
- "---|---------------------------------------------------------------------",
- " ")
-
- # Function for creating the directory
- createDir <- function(x){
- paste0(path, '/', x)
- }
-
- createFiles <- function(x){
- file.path(path, paste0(x, '/ReadMe.md'))
- }
-
- readme <- readme[template]
-
- pathnames <- sapply(names(readme), createDir)
- dir_created <- lapply(pathnames, dir.create, showWarnings = F, recursive = T)
- con <- lapply(names(readme), createFiles)
- doNotOverwrite <- sapply(con, file.exists)
- readme <- readme[!doNotOverwrite]
- con <- con[!doNotOverwrite]
- files_created <- mapply(writeLines, lapply(readme, paste0, collapse = '\n'), con)
-}
diff --git a/R/default.R b/R/default.R
new file mode 100644
index 0000000..5fceb98
--- /dev/null
+++ b/R/default.R
@@ -0,0 +1,272 @@
+#' Set Global Default Analyst Value
+#'
+#'
+#' This function allows you to set the default analyst at the user level and
+#' if possible changes the default analyst in the template for new projects.
+#'
+#' @param analyst_name A string containing the analyst name
+#' @param update_template Bool whether or not to update analyst in the project template.
+#' @return A message stating the name has been changed.
+#' @keywords options Analyst
+#' @export
+#'
+set_global_default_analyst <- function(analyst_name,update_template=FALSE){
+ analyst_name <- check_string_param_value(analyst_name,'analyst_name')
+ # Save to user cida_defaults.dcf
+ set_default_value('analyst_name',analyst_name)
+
+ # Save to project templates
+ if(update_template){
+ set_template_analyst(analyst_name)
+ }
+ return(paste('The default analyst name has been changed to',
+ analyst_name))
+}
+
+#' Get Default Analyst Value
+#'
+#'
+#' This function allows you to get the default analyst.
+#'
+#' @return The default analyst or an empty string if not set.
+#' @keywords options Analyst
+#' @export
+#'
+get_global_default_analyst <- function(){
+ value <- get_default_value('analyst_name')
+ return(value)
+}
+
+
+
+#' Remove Default Analyst from ~/cida_defaults.dcf
+#'
+#' This function removes the default analyst set with set_global_default_analyst()
+#' from the users ~/cida_defaults.dcf.
+#'
+#'
+#' @return Message indicating success or failure
+#' @keywords Analyst remove
+#' @export
+#'
+#'
+remove_global_default_analyst <- function(){
+ to_save <- NULL
+ defaults <- read_global_defaults()
+ msg <- ""
+ if(!is.null(defaults)){
+ to_save <- list()
+ for (element in names(defaults)) {
+ if(element!="analyst_name"){
+ to_save[element]=defaults[element]
+ }
+ }
+ write_global_defaults(to_save)
+ msg <- paste('The default analyst has been removed.')
+ }else{
+ warning("Analyst not removed: global default file not found.")
+ msg <- paste("Analyst not removed: global default file not found.")
+ }
+ return(msg)
+}
+
+
+
+#' Sets a default drive path in ~/cida_defaults.dcf
+#'
+#' This function sets a default path at the user level to access the project
+#' drive. If the drive is not detected automatically this file will be used to
+#' set a default path if set.
+#'
+#' @param path Path to the main project(CIDA) drive
+#'
+#' @return Message that path was set.
+#' @export
+#'
+set_global_default_path <- function(path=""){
+ path <- check_string_param_value(path,'global_default_path')
+ set_default_value('path',path)
+ return(paste('The default project path has been changed to',path))
+}
+
+#' removes the default drive path in ~/cida_defaults.dcf
+#'
+#' This function removed the default path at the user level to access the project
+#' drive.
+#'
+#' @export
+#'
+remove_global_default_path <- function(){
+ set_default_value('path',"")
+}
+
+
+#' Get Default drive path
+#'
+#'
+#' This function returns the user level default drive path set in ~/cida_defaults.dcf
+#'
+#' @return The default path
+#' @keywords options path
+#' @export
+#'
+get_global_default_path <- function(){
+ path <- ''
+ path <- get_default_value('path')
+ return(path)
+}
+
+#' Sets a default parameter in ~/cida_defaults.dcf
+#'
+#' This function sets a default parameter at the user level.
+#'
+#' @param parameter parameter name
+#' @param value new value
+#'
+#'
+#' @export
+#'
+set_default_value <- function(parameter,value){
+ defaults <- get_defaults()
+ if(parameter %in% names(defaults)){
+ defaults[parameter] <- value
+ }else{
+ defaults[parameter] <- value
+ }
+ save_global_defaults(defaults)
+}
+
+#' Get a specific user level default
+#'
+#'
+#' This function returns a specific user level defaults set in ~/cida_defaults.dcf
+#'
+#' @param parameter The name of the specific parameter to lookup.
+#' @return The user level defaults named parameter
+#' @keywords options path
+#' @export
+#'
+get_default_value <- function(parameter){
+ default_value <- ""
+ defaults <- get_defaults()
+ if( parameter %in% names(defaults)){
+ default_value <- defaults[parameter][1,1]
+ }else{
+ warning("Parameter:",parameter," does not exist in default values.\n")
+ }
+ return(default_value)
+}
+
+
+#' Get a list of all user level defaults
+#'
+#'
+#' This function returns the user level defaults set in ~/cida_defaults.dcf
+#'
+#' @return The user level defaults
+#' @keywords options path
+#' @export
+#'
+get_defaults <- function(){
+ default_values <- NULL
+
+ tmp <- read_global_defaults()
+ if(!is.null(tmp)){
+ default_values <- tmp
+ }
+ return(default_values)
+}
+
+#' Get CIDA Defaults read from ~/cida_defaults.dcf
+#' Use fs to get a cross platform path to the user directory to store
+#' cida_defaults.dcf then read cida_defaults.dcf and return the object.
+#'
+#' @returns the default object stored in cida_defaults.dcf
+#'
+#' @noRd
+#' @noMd
+#'
+read_global_defaults <- function(){
+ default <- NULL
+
+ home_dir <- fs::path_home()
+
+ path <-fs::path_join(c(home_dir,"/cida_defaults.dcf"))
+
+ if(file.exists(file.path(path))){
+ default <- read.dcf(file.path(path), all = T)
+ }else{
+ warning("~/cida_defaults.dcf at full path:",path," does not exist.\nNothing was loaded.")
+ }
+
+ return(default)
+}
+
+#' Write global defaults to ~/cida_defaults.dcf
+#' Use fs to get a cross platform path to the user directory to store
+#' cida_defaults.dcf then write cida_defaults.dcf.
+#'
+#' @returns bool for success or failure
+#'
+#' @noRd
+#' @noMd
+#'
+
+write_global_defaults <- function( defaults_to_write){
+ home_dir <- fs::path_home()
+ path <-fs::path_join(c(home_dir,"/cida_defaults.dcf"))
+ write.dcf(defaults_to_write, file.path(path))
+
+ return(TRUE)
+}
+
+#' Save CIDA Defaults to ~/cida_defaults.dcf
+#'
+#' Use fs to get a cross platform path to the user directory to store
+#' cida_defaults.dcf then save cida_defaults.dcf avoids inadvertent removal of
+#' default values by first reading in the file, then overwriting the values provided,
+#' preserving any not specified. To remove default values use remove_global_default().
+#'
+#' @param new_default a list of new default values
+#'
+#' @noRd
+#' @noMd
+#'
+save_global_defaults<- function(new_default){
+ to_save <- NULL
+
+ defaults <- read_global_defaults()
+ if(!is.null(defaults) ){
+ to_save <- defaults
+ for (element in names(new_default)) {
+ to_save[element]=new_default[element]
+ }
+ }else{
+ to_save <- new_default
+ }
+ write_global_defaults(to_save)
+}
+
+
+#' Save template analyst to CIDA project template
+#'
+#' Save analyst to the CIDA project template for new projects.
+#'
+#' @param analyst_name Name of the default analyst for new projects.
+#'
+#' @noRd
+#' @noMd
+#'
+
+set_template_analyst <- function(analyst_name=""){
+ site_path = R.home(component = "home")
+ project_setup <- paste0(site_path,
+ '/library/CIDAtools/rstudio/',
+ 'templates/project/proj_setup.dcf')
+ if(file.access(project_setup, 2) == -1)
+ stop(paste0('You do not have permission to change\n',
+ 'New CIDA Project Template'))
+ DCF <- read.dcf(file.path(project_setup), all = T)
+ DCF$Default[DCF$Parameter == 'analyst' & !is.na(DCF$Parameter)] <- analyst_name
+ write.dcf(DCF, file.path(project_setup))
+}
diff --git a/R/find_nearest.R b/R/find_nearest.R
index 4814c8d..4a540a1 100644
--- a/R/find_nearest.R
+++ b/R/find_nearest.R
@@ -1,4 +1,4 @@
-#' Find the nearest observation to another observation
+#' Find the nearest observation to another observation - To be deprecated
#'
#'
#' This function finds the nearest y to every x. Y's may be duplicated.
@@ -21,6 +21,9 @@
find_nearest <- function(x, y,
direction = c('both', 'ascending', 'descending'),
returnIndex = FALSE) {
+
+ deprecation_warn("find_nearest.find_nearest")
+
direction <- match.arg(direction)
a <- switch(direction, both = T, ascending = T, descending = F)
d <- switch(direction, both = T, ascending = F, descending = T)
@@ -59,7 +62,7 @@ find_nearest <- function(x, y,
-#' Internal function for find_nearest
+#' Internal function for find_nearest - To be deprecated
#'
#'
#' @param x first value
@@ -69,6 +72,9 @@ find_nearest <- function(x, y,
#' @describeIn find_nearest function for finding lower(upper) value
getlower <- function(x, y, upper = FALSE){
+
+ deprecation_warn("find_nearest.getlower")
+
n <- length(y)
z <- c(y, x)
j <- i <- order(z, decreasing = upper)
diff --git a/R/misc_fns.R b/R/misc_fns.R
index 34c7549..82cbbd5 100644
--- a/R/misc_fns.R
+++ b/R/misc_fns.R
@@ -1,45 +1,6 @@
-#' Set Default Analyst Value
-#'
-#'
-#' This function allows you to set the option CIDAtools.analyst permanently
-#' (until you change it or reinstall CIDAtools) and will
-#' simultanesouly change the default in New Cida Project Template.
-#'
-#' @param AnalystName A string containing the analyst name
-#' @return A message stating the name has been changed.
-#' @keywords options Analyst
-#' @export
-#'
-setAnalyst <- function(AnalystName){
- if(!is.character(AnalystName)) stop('Analyst Name must be a character string')
- if(length(AnalystName) > 1) {
- warning('Only First String is Used')
- AnalystName <- AnalystName[1]
- }
- AnalErr <- try(setPermanentAnalyst(AnalystName), silent = T)
- msg1 <- NULL
- if(!is.null(AnalErr)) msg1 <- paste0('Default Analyst can not be ',
- 'saved permanently.\n',
- 'You will need to set for each ',
- 'R session.\n')
- site_path = R.home(component = "home")
- Project_setup <- paste0(site_path,
- '/library/CIDAtools/rstudio/',
- 'templates/project/proj_setup.dcf')
- if(file.access(Project_setup, 2) == -1)
- stop(paste0(msg1,
- 'You do not have permission to change\n',
- 'New CIDA Project Template'))
- DCF <- read.dcf(file.path(Project_setup), all = T)
- DCF$Default[DCF$Parameter == 'analyst' &
- !is.na(DCF$Parameter)] <- AnalystName
- write.dcf(DCF, file.path(Project_setup))
- return(paste('The default analyst name has been changed to',
- getOption('CIDAtools.analyst')))
-}
-#' Get pretty numbers of rows
+#' Get pretty numbers of rows - To be deprecated
#'
#'
#' Retrieve the number of rows in dataframe of matrix with commas inserted for
@@ -54,10 +15,11 @@ setAnalyst <- function(AnalystName){
nrowP <- function(x){
+ deprecation_warn("misc_fns.nrowP")
format(nrow(x), big.mark = ',', trim = T)
}
-#' Get pretty number of levels
+#' Get pretty number of levels - To be deprecated
#'
#'
#' Just a wrapper for format(nlevels) with big.mark = , and trim = T
@@ -69,75 +31,13 @@ nrowP <- function(x){
#'
nLevelsP <- function(x){
+ deprecation_warn("misc_fns.nLevelsP")
format(nlevels(x), big.mark = ',', trim = T)
}
-#' Set Default Analyst Value
-#'
-#'
-#' This is an internal function that writes the Default Analyst name to the
-#' users Rprofile.
-#'
-#' @param Name A string containing the analyst name
-#'
-setPermanentAnalyst <- function(Name){
- options(CIDAtools.analyst = Name)
- fname = file.path("~/.Rprofile")
- opts <- character()
- if(file.exists(fname)){
- opts <- readLines(fname)
- }
- opts[grep('options\\(CIDAtools.analyst = ', opts, invert = T)] -> opts
- opts <- c(opts, paste0("options(CIDAtools.analyst = '",
- paste0(Name), "')"))
- if(!file.create(fname, showWarnings = F))
- stop()
- writeLines(opts, fname)
-}
-#' Remove Default Analyst from ~/.Rprofile
-#'
-#' This function removes the default analyst set with setAnalyst() from the users
-#' .Rprofile. If this is the only entry in .Rprofile it will remove the file as well.
-#'
-#' @param quiet should a message indicating result be returned, if TRUE will only
-#' return TRUE or FALSE
-#'
-#' @return Message indicating sucess or failue
-#' @keywords Analyst remove
-#' @export
-#'
-#'
-removeAnalyst <- function(quiet = F){
- fname = file.path("~/.Rprofile")
- if(file.access(fname, 4) != 0){
- if(!quiet){
- return('User does not have an Rprofile or Rprofile can not be read')
- }
- return(FALSE)
- }
- opts <- readLines(fname)
- opts[grep('options\\(CIDAtools.analyst = ', opts, invert = T)] -> opts
- if(file.access(fname, 2) != 0){
- if(!quiet){
- return('You do not have permission to write to users Rprofile')
- }
- return(FALSE)
- }
- if(length(opts) == 0){
- file.remove(fname)
- if(!quiet){
- return('Users .Rprofile is empty and was deleted')
- }
- return(TRUE)
- }
- writeLines(opts, fname)
- if(!quiet)
- return('options(CIDAtools.analyst) has been removed from users profile')
- return(TRUE)
-}
-#' Convert Interval Notation
+#' Convert Interval Notation - To be deprecated
#'
#' Converts a vector from Interval Notation to less than equal to, less than,
#' etc.
@@ -149,6 +49,7 @@ removeAnalyst <- function(quiet = F){
#' @export
#'
convertIntervalNotation <- function(x){
+ deprecation_warn("misc_fns.convertIntervalNotation")
if(!is.character(x)) stop('x must be a character vector')
x <- gsub('\\(-Inf, ', '', x)
x <- gsub(',Inf\\)', '', x)
@@ -160,7 +61,7 @@ convertIntervalNotation <- function(x){
return(x)
}
-#' Round and don't drop trailing zeros
+#' Round and don't drop trailing zeros - To be deprecated
#'
#' Shorter wrapper for format(x, digits = n, nsmall = n)
#'
@@ -178,10 +79,11 @@ convertIntervalNotation <- function(x){
#'
#'
Round <- function(x, n){
+ deprecation_warn("misc_fns.Round")
format(x, digits = n, nsmall = n)
}
-#' Sum ignoring NAs
+#' Sum ignoring NAs - To be deprecated
#'
#' Will sum values returning NA only if all values are NA, otherise will ignore
#'
@@ -213,6 +115,7 @@ Round <- function(x, n){
sum_ignore_NA <- function(...){
+ deprecation_warn("misc_fns.sum_ignore_NA")
arguments <- list(...)
arguments <- lapply(arguments, unlist)
x <- sapply(arguments, length)
@@ -226,7 +129,7 @@ sum_ignore_NA <- function(...){
})
}
-#' Vectorized power estimates
+#' Vectorized power estimates - To be deprecated
#'
#'
#' This function allows you to use power.t.test, power.prop.test, etc in
@@ -253,7 +156,7 @@ sum_ignore_NA <- function(...){
#'
vec_power <- function(fun = stats::power.t.test, ...){
-
+ deprecation_warn("misc_fns.vec_power")
args <- list(...)
params <- expand.grid(args, stringsAsFactors = FALSE)[,length(args):1]
@@ -270,17 +173,14 @@ vec_power <- function(fun = stats::power.t.test, ...){
return(na.omit(results))
}
-# Helper for pwr package version of power fns.
+#' Helper for pwr package version of power fns. - To be deprecated
+#' @param x description
+#' @param ... description
+#'
tidy.power.htest <- function(x, ...) {
+ deprecation_warn("misc_fns.tidy.power.htest")
class(x) <- "list"
as.data.frame(x)
}
-# helper function to cleanup project location
-proj.location.handler <- function(loc="") {
- loc <- gsub("/Volumes/sph-cida", "", loc)
- loc <- gsub("P:/", "", loc)
- loc <- gsub(".*BRANCHES", "BRANCHES", loc)
- loc <- gsub("/$", "", loc)
- return(loc)
-}
+
diff --git a/R/project.R b/R/project.R
new file mode 100644
index 0000000..492d0ba
--- /dev/null
+++ b/R/project.R
@@ -0,0 +1,649 @@
+#' Get Project drive path
+#'
+#' This function attempts to get the proper path for the Project(CIDA) drive either on
+#' Windows or Mac automatically. It returns the full CIDA drive(remote) path
+#' with the relative path (if provided) appended to the drive path.
+#'
+#' If open_project() has been called with a remote path specified the remote path
+#' will be used first.
+#'
+#' If that is not set it will try to determine the drive path. If the expected
+#' path is not found it will try to load the project metadata path and if that
+#' fails it looks for a global default path in the user cida_defaults.dcf file.
+#'
+#' @param file (optional) Path to subdirectory/file within the main project(CIDA) drive
+#'
+#' @return Full (absolute) file path of project(CIDA) drive plus the subdirectory/file provided.
+#' @export
+#'
+#' @examples
+#' # Read data from P1234PIname project
+#' \dontrun{
+#' df <- read.csv(get_project_drive_path("BRANCHES/Pulmonary/P1234PIname/DataRaw/data.csv"))
+#' }
+#'
+
+get_project_drive_path <- function(file = "") {
+ path <- ""
+ if(options("cida_tools.remote_current_project_path") != ""){
+ #get project path
+ path <- options("cida_tools.remote_current_project_path")
+ #remove everything after BRANCHES
+ path <- sub("/BRANCHES.*","",path)
+ }else{
+ # Get operating system (note that MacOS and Linux return unix)
+ os <- .Platform$OS.type
+
+
+ ## TODO Set a global default path somewhere and then iterativly parse each
+ # sub-directory to test instead of these static sub-directories of the CIDA path
+
+ if (os == "unix") { # MacOS/Linux
+
+ # Four potential places drive could exist based on path used for mapping
+ # and case sensitivity of the file system
+ # Then check manually set project data in .ProjData/Data.dcf
+ if (dir.exists("/Volumes/sph-cida/BRANCHES")) {
+ path <- "/Volumes/sph-cida/BRANCHES"
+ } else if(dir.exists("/Volumes/branches")){
+ path <- "/Volumes/branches"
+ }else if(dir.exists("/Volumes/sph/SPH-CIDA/BRANCHES")){
+ path <- "/Volumes/sph/SPH-CIDA/BRANCHES"
+ }else if(dir.exists("/Volumes/dept")){
+ path <- "/Volumes/dept/SPH/SPH-CIDA/BRANCHES"
+ }else if (dir.exists("/Volumes/SPH-CIDA")) {
+ path <- "/Volumes/SPH-CIDA/BRANCHES"
+ }else if(dir.exists("/Volumes/SPH")){
+ path <- "/Volumes/SPH/SPH-CIDA/BRANCHES"
+ }else if(dir.exists("/Volumes/DEPT")){
+ path <- "/Volumes/DEPT/SPH/SPH-CIDA/BRANCHES"
+ }else {
+ path <- get_default_path()
+ if(path==""){
+ stop("Nothing found at /Volumes/dept || SPH || SPH-CIDA || BRANCHES",
+ " Please ensure drive is mounted and you have entered your",
+ " password to access the drive (and are logged into the VPN if",
+ " needed.)",
+ " If still experiencing issues try set_project_data_path() or ",
+ " set_global_default_path()"
+ )
+ }else{
+ if(! dir.exists(path)){
+ stop("Automatic Path: Failed\nDefault Path:",path,": Failed\n",
+ " If still experiencing issues try set_project_data_path() or ",
+ " set_global_default_path()")
+ }
+ }
+ }
+
+ } else if (os == "windows") { # Windows
+
+ # Only one spot drive can be mounted for Windows
+ if (dir.exists("P:/")) {
+ path <- "P:/"
+ if(dir.exists("P:/dept/SPH/SPH-CIDA/BRANCHES")){
+ path <- "P:/dept/SPH/SPH-CIDA/BRANCHES"
+ }else if(dir.exists("P:/SPH/SPH-CIDA/BRANCHES")){
+ path <- "P:/SPH/SPH-CIDA/BRANCHES"
+ }else if(dir.exists("P:/SPH-CIDA/BRANCHES")){
+ path <- "P:/SPH-CIDA/BRANCHES"
+ }else if(dir.exists("P:/BRANCHES")){
+ path <- "P:/BRANCHES"
+ }
+ }else {
+ path <- get_default_path()
+ if(path==""){
+ stop("Nothing found at P:/.",
+ " Please ensure drive is mounted and you have entered your",
+ " password to access the drive (and are logged into the VPN if",
+ " needed.)",
+ " If still experiencing issues try set_project_data_path() or ",
+ " set_global_default_path()"
+ )
+ }else{
+ if(! dir.exists(path)){
+ stop("Automatic Path: Failed\nDefault Path:",path,": Failed (does not exist)\n",
+ " If still experiencing issues try set_project_data_path() or ",
+ " set_global_default_path()")
+ }
+ }
+ }
+ } else {
+ stop("Operating system could not be identified")
+ }
+ }
+
+ # Combine CIDA drive path with user provided subdirectory/file
+ if(file !=""){
+ file_path <- file.path(path, file)
+ }else{
+ file_path <- path
+ }
+
+ # Check if full path exists (first as file, second as directory)
+ if (!dir.exists(file_path) & !file.exists(file_path)) {
+
+ # TODO: consider adding function to search for partial paths and suggest
+ # alternatives
+
+ stop("Nothing found at path ", file_path,
+ "\nCheck spelling of path, and ensure drive is mounted and you have",
+ " entered your password to access the drive (and are logged into the",
+ " VPN if needed.)")
+ }
+
+ # Return full path
+ return(fs::path(file_path))
+}
+
+
+
+#'Create Project Directory + readme files
+#'
+#'This function creates the standard project organization structure for CIDA
+#'within a folder that already exists.
+#'
+#'@param path Where should they be created? Default is the working directory.
+#'@param template Which subdirectories to create
+#'@param project_name Name of project, (required)
+#'@param pi Name of PI and credentials, or "" for blank
+#'@param analyst Name of Analyst(s), (required)
+#'@param data_location Location of project on CIDA Drive, or "" for blank
+#'@param git_location Location project on GitHub
+#'@return This function creates the desired project subdirectories and readmes,
+#' as well as a standard .gitignore file files. It will not overwrite the file
+#' however if it does not exist. It does not return anything.
+#'@keywords project createproject
+#'
+#'@seealso proj_setup() is the internal wrapper for this that gets called when
+#' using the RStudio GUI to create a project
+#'
+#'@export
+create_project <- function(path = getwd(),
+ template = c('Admin', 'Background', 'Code', 'DataRaw',
+ 'DataProcessed', 'Dissemination', 'Reports'),
+ project_name, pi = "", analyst, data_location = "",
+ git_location = "") {
+ if (missing(project_name) || !nzchar(trimws(project_name))){
+ stop(" 'project_name' is required and cannot be empty.", call. = FALSE)
+ }
+ if( ! dir.exists(path) ){
+ dir.create(path, recursive = TRUE, showWarnings = FALSE)
+ }
+
+ # has meta been provided?
+ # meta <- !all(c(project_name, pi, analyst, data_location,git_location) %in% "")
+
+
+ # set which ReadMe.md files to create
+ template <- match.arg(template, several.ok = T)
+
+ # Overall readme
+
+ readme <- c(paste0("**Project Name**: ", project_name, " "),
+ paste0("**PI**: ", pi, " "),
+ paste0("**Analyst**: ", analyst, " "),
+ paste0("**CIDA drive Location**: ", proj_location_handler(data_location), " "),
+ paste0("**GitHub Location**: ", git_location, " "),
+ "",
+ "Details about the folders:",
+ '',
+ "File | Description",
+ "---|----------------------------------------------------------",
+ paste("Admin | contains the scope of work and other",
+ "administrative documents"),
+ paste("Background | contains the background information for",
+ "the analysis"),
+ "Code | contains all R scripts for this project",
+ "DataRaw | contain all raw data provided by investigators",
+ "DataProcessed | contains the processed data used for analysis",
+ paste("Dissemination | contains any materials produced for",
+ "dissemination, ie. Abstracts, Posters, Papers"),
+ "Reports | contains all output, rmarkdown files and report")
+
+
+ # write to readme file
+ if(!file.exists(file.path(path, "README.md")))
+ writeLines(paste0(readme, collapse = '\n'),
+ con = file.path(path, "README.md"))
+
+ # Create subdirectory readmes
+ create_readme(template = template, path = path)
+
+ # Add .ProjData directory containing metadata
+ #if(meta){
+ if (! dir.exists(paste0(path, '/.ProjData'))){
+ dir.create(paste0(path, '/.ProjData'))
+ }
+ proj_data <- list(ProjectName = project_name, PI = pi,
+ analyst = analyst, datalocation = data_location,
+ gitlocation = git_location)
+ write.dcf(proj_data, file.path(path, '/.ProjData/Data.dcf'))
+ #}
+
+ # add to current gitignore if exists
+ if(file.exists(file.path(path, '.gitignore'))){
+ gitignore <- readLines(con = file.path(path, '.gitignore'))
+ } else {
+ gitignore <- NULL
+ }
+
+ # add R template gitignore
+ # (source: https://github.com/github/gitignore/blob/master/R.gitignore)
+ gitignore <- paste0(c(gitignore,
+ "# History files",
+ ".Rhistory",
+ ".Rapp.history",
+
+ "# Session Data files",
+ ".RData",
+
+ "# User-specific files",
+ ".Ruserdata",
+
+ "# Example code in package build process",
+ "*-Ex.R",
+
+ "# Output files from R CMD build",
+ "/*.tar.gz",
+
+ "# Output files from R CMD check",
+ "/*.Rcheck/",
+
+ "# RStudio files",
+ ".Rproj.user/",
+
+ "# produced vignettes",
+ "vignettes/*.html",
+ "vignettes/*.pdf",
+
+ paste0("# OAuth2 token, see https://github.com/",
+ "hadley/httr/releases/tag/v0.3"),
+ ".httr-oauth",
+
+ "# knitr and R markdown default cache directories",
+ "/*_cache/",
+ "/cache/",
+
+ "# Temporary files created by R markdown",
+ "*.utf8.md",
+ "*.knit.md"), collapse = '\n')
+
+ # by file type
+ gitignore <- paste0(c(gitignore,
+ "# R Data files",
+ "*.RData",
+ "*.rda",
+ "*.rdata",
+ "*.rda",
+ "# Text files",
+ "*.csv",
+ "*.txt",
+ "*.dat",
+ "# Excel",
+ "*.xls*",
+ "# SAS",
+ "*.sas7bdat",
+ "*.xport",
+ "# Access",
+ "*.mdb"), collapse = '\n')
+
+ # by Folder
+ gitignore <- paste0(c(gitignore,
+ "DataRaw/*",
+ "DataProcessed/*",
+ "!*/README.md"), collapse = '\n')
+
+ writeLines(gitignore, con = file.path(path, '.gitignore'))
+
+ # Create .Rproj file
+ rproj <- paste0(c("Version: 1.0",
+ "",
+ "RestoreWorkspace: Default",
+ "SaveWorkspace: Default",
+ "AlwaysSaveHistory: Default",
+ "",
+ "EnableCodeIndexing: Yes",
+ "UseSpacesForTab: Yes",
+ "NumSpacesForTab: 2",
+ "Encoding: UTF-8",
+ "",
+ "RnwWeave: knitr",
+ "LaTeX: pdfLaTeX"), collapse = "\n")
+
+ if(!file.exists(file.path(path, paste0(basename(path), ".Rproj"))))
+ writeLines(rproj, con = file.path(path, paste0(basename(path), ".Rproj")))
+
+ # TODO: We should search for both the global (home directory) and local (project directory) .Rprofiles.
+ # TODO: This uses '~', is this portable to Windows (and is RProfile stored in the same place on Windows)?
+ rprofile <- paste0(c('if( file.exists(fs::path_expand("~/.Rprofile") ) ){',
+ 'source(path.expand("~/.Rprofile"))',
+ '}',
+ 'library(CIDATools)',
+ paste0('CIDATools::open_project(localpath="',path,'")')),
+ collapse="\n")
+ if(!file.exists(file.path(path,"/.Rprofile")))
+ writeLines(rprofile, con = file.path(path,"/.Rprofile"))
+
+ ## Copy over SOW
+ message("Project created. Please remember to copy the scope of work to to Admin/ subdirectory.")
+
+ invisible(template)
+}
+
+proj_setup <- function(path, ...){
+ # ensure path exists
+ dots <- list(...)
+ project_name <- paste0(path)
+ analyst_val <- dots$analyst
+ if(is.null(analyst_val) || !nzchar(trimws(analyst_val))){
+ analyst_val <- "UNKNOWN - please update with set_project_analyst()"
+ warning("No analyst name was provided. Please set it with",
+ "CIDAtools::set_project_analyst('Your Name').",
+ call. = FALSE)
+ }
+ create_project(path, project_name = project_name, pi = dots$PI,
+ analyst = analyst_val, data_location = dots$datalocation,
+ git_location = dots$gitlocation)
+
+ # Commenting out as this is written in create_project.
+ #dir.create(paste0(path, '/.ProjData'))
+ #proj_data <- list(ProjectName = project_name, PI = dots$PI,
+ # analyst = dots$analyst, datalocation = dots$datalocation,
+ # gitlocation = dots$gitlocation)
+ #write.dcf(proj_data, file.path(path, '/.ProjData/Data.dcf'))
+
+}
+
+create_readme <- function(template = c('Admin', 'Background', 'Code', 'DataRaw',
+ 'DataProcessed', 'Dissemination',
+ 'Reports'), path = getwd()){
+ # set which ReadMe.md files to create
+ template <- match.arg(template, several.ok = T)
+
+ # create list with lines for each template
+ readme <- list()
+
+ readme$Admin <- c("# Admin ",
+ " ",
+ "This folder contains the scope of work and other relevant files from CIDA admin. ",
+ " ",
+ "Details about the files: ",
+ " ",
+ "File | Description",
+ "---|---------------------------------------------------------------------",
+ " ",
+ "")
+ readme$Background <- c("# Background ",
+ " ",
+ "This folder contains documents provided by investigators and the data analysis plan. ",
+ " ",
+ "Details about the files: ",
+ " ",
+ "File | Description",
+ "---|---------------------------------------------------------------------",
+ " ")
+ readme$Code <- c("This folder contains all the code. ",
+ " ",
+ "Details about the files in this folder:",
+ " ",
+ "File | Description",
+ "---|---------------------------------------------------------------------",
+ " ")
+ readme$DataProcessed <- c("# Processed Data ",
+ " ",
+ "Scripts that created the files in this folder: ",
+ " ",
+ "File | Script | Description",
+ "---|------------------|---------------------------------------------------",
+ " ")
+ readme$DataRaw <- c("# Raw Data",
+ " ",
+ "Details about the files: ",
+ " ",
+ "File | Details",
+ "---|---------------------------------------------------------------------",
+ " ",
+ " ")
+
+ readme$Dissemination <- c("# Dissemination",
+ " ",
+ "This folder contains abstracts, posters, papers and anything else produced for dissemination. ",
+ " ",
+ "Details about the files: ",
+ " ",
+ "File | Description",
+ "---|---------------------------------------------------------------------",
+ " ",
+ " ")
+ readme$Reports <- c("# Reports",
+ " ",
+ "This folder contains the rmarkdown scripts and pdf output of reports. ",
+ " ",
+ "Details about the files: ",
+ " ",
+ "File | Description",
+ "---|---------------------------------------------------------------------",
+ " ")
+
+ # Function for creating the directory
+ createDir <- function(x){
+ paste0(path, '/', x)
+ }
+
+ createFiles <- function(x){
+ file.path(path, paste0(x, '/README.md'))
+ }
+
+ readme <- readme[template]
+
+ pathnames <- sapply(names(readme), createDir)
+ dir_created <- lapply(pathnames, dir.create, showWarnings = F, recursive = T)
+ con <- lapply(names(readme), createFiles)
+ doNotOverwrite <- sapply(con, file.exists)
+ readme <- readme[!doNotOverwrite]
+ con <- con[!doNotOverwrite]
+ files_created <- mapply(writeLines, lapply(readme, paste0, collapse = '\n'), con)
+}
+
+
+#' pull project files from remote directory
+#'
+
+#'Backup Project Directory
+#'
+#'This function backs up a CIDA project to the shared (P) CIDA drive. The backup directory
+#'can either be existing (in which only changed files/folders are updated), or
+#'nonexisting, in which case a full project backup is created.
+#'
+#'@param path_from Path from where the folders should be copied (project
+#' directory location).
+#'@param path_to Path to where the folders should be copied (P drive, only used
+#' if specified).
+#'@param exclude files/folders NOT to be backed up to the P-drive (useful for
+#'larger files that don't change often). Currently not used.
+#'@param recreate should backup be created from the ground up?
+#' (can take longer, but useful for projects with many changes)
+#' @param data_only should only subdirs including "data" (DataRaw/ and DataProcessed/) be backed up?
+#' @param readme forces backup of project readme
+#' @return This function has verbose output to ensure the back up is working, and
+#' ultimately returns a success indicator that's returned by file.copy.
+#'
+#'@export
+backup_project <- function(path_from = getwd(),
+ path_to = NULL,
+ exclude = c(".DS_Store", ".Rproj.user", ".git"),
+ recreate = FALSE,
+ data_only = TRUE,
+ readme = TRUE) {
+
+ # Check args, make into absolute paths
+ path_from <- normalizePath(path_from)
+
+ # Get proper path to Shared drive
+ if(missing(path_to)) {
+ path_to <- get_project_location()
+ if(path_to == "")
+ stop("Please first set project location, e.g., CIDAtools::set_project_location('BRANCHES/EmergencyMedicine/ThisProject')")
+
+ if(!dir.exists(CIDAtools::get_project_drive_path()))
+ stop("Please ensure the CIDA drive is mounted, or set `path_to`")
+
+ }
+
+ path_to <- normalizePath(path_to)
+
+ ## Check if specific project folder exists on P drive
+ backup_path <- file.path(path_to)
+ if(!dir.exists(backup_path)) {
+ message("Note: '", backup_path, "' not found; directory was created.")
+ dir.create(backup_path)
+ } else if (!recreate){
+ message("Note: backup path already exists, and will be updated unless cancelled.")
+ message("Backup path:\n", backup_path,
+ "\nProject path:\n",
+ path_from)
+ } else {
+ message("Note: backup path already exists, and will be completely overwritten since recreate == TRUE.")
+ message("Backup path:\n", backup_path,
+ "\nProject path:\n",
+ path_from, "\n\nType 'yes' to confirm.")
+ delete_old <- readline()
+
+ if(delete_old != "yes")
+ stop("Cancelled")
+ unlink(backup_path, recursive=TRUE)
+ dir.create(backup_path)
+ }
+
+ message("\nDetermining current backup situation...")
+
+ files_to_copy <-
+ list.files(path_from, recursive = T, all.files = T)
+ dirs_to_copy <- list.dirs(path_from, recursive = T, full.names = F)[-1]
+
+ if(length(exclude)) {
+ files_to_exclude <- c(
+ unlist(sapply(exclude[dir.exists(exclude)], list.files, recursive = TRUE,
+ all = TRUE, full.names = T)),
+ exclude[!dir.exists(exclude)])
+
+ files_to_copy <- files_to_copy[!(files_to_copy %in% files_to_exclude)]
+
+ dirs_to_exclude <- c(
+ unlist(sapply(exclude[dir.exists(exclude)], list.dirs, recursive = TRUE,
+ full.names = T)))
+
+ dirs_to_copy <- dirs_to_copy[!(dirs_to_copy %in% dirs_to_exclude)]
+ }
+
+ if(data_only) {
+ string_matches <- "dataraw|dataprocessed"
+ if(readme)
+ string_matches <- "readme|dataraw|dataprocessed"
+
+ # find large files (>= 250 MB)
+ large_idx <- file.size(files_to_copy)/1e6 >= 250
+
+ # find file matches
+ file_matches <- grepl(string_matches, files_to_copy, ignore.case = TRUE)
+ dir_matches <- grepl(string_matches, dirs_to_copy, ignore.case = TRUE)
+
+ files_to_copy <- files_to_copy[large_idx | file_matches]
+ dirs_to_copy <- dirs_to_copy[large_idx | dir_matches]
+ }
+
+ ## Check if any files can be ignored using time last modified time
+ check <- file.exists(file.path(backup_path, files_to_copy))
+ if(any(check)) {
+ to_mtime <- file.mtime(file.path(backup_path, files_to_copy))
+
+ # If no file found, set last modified time into future (kind of a hack)
+ to_mtime[is.na(to_mtime)] <- Sys.time() +500
+
+ from_mtime <- file.mtime(file.path(path_from, files_to_copy))
+ files_to_copy <- files_to_copy[abs(difftime(to_mtime, from_mtime, units = "secs")) > 1]
+ }
+
+ # Check and don't copy dirs if they already exist
+ dirs_to_copy <- dirs_to_copy[!dir.exists(file.path(backup_path, dirs_to_copy))]
+
+ message("\nI'm about to create or update ",length(dirs_to_copy)," subdirectories and ",
+ length(files_to_copy), " files.",
+ "'\nType 'yes' to confirm, or 'list' to list changes.")
+ val <- readline()
+ if(val == "list") {
+ cat("Subdirs:", dirs_to_copy, sep = "\n")
+ cat("\n\nFiles:", files_to_copy, sep = "\n")
+ message("'\n\n Type 'yes' to confirm.")
+ val <- readline()
+ }
+
+ stopifnot(val == "yes")
+
+ if(length(dirs_to_copy)) {
+ message("Creating ", length(dirs_to_copy)," subdirectories...")
+ pb <- dplyr::progress_estimated(length(dirs_to_copy))
+ r1 <- sapply(1:length(dirs_to_copy), function(i) {
+ pb$tick()$print()
+ dir.create(file.path(backup_path, dirs_to_copy[i]))
+ })
+ } else
+ r1 <- T
+
+ if(length(files_to_copy)) {
+ message("\nCopying/updating ", length(files_to_copy), " files...")
+ pb <- dplyr::progress_estimated(length(files_to_copy))
+ r2 <- sapply(1:length(files_to_copy), function(i) {
+ pb$tick()$print()
+ file.copy(file.path(path_from, files_to_copy[i]),
+ file.path(backup_path, files_to_copy[i]),
+ overwrite = TRUE, copy.date = TRUE)
+
+ })
+ } else
+ r2 <- T
+
+ result <- all(r1) & all(r2)
+ create_backup_info(backup_path)
+
+ return(invisible(result))
+}
+
+create_backup_info <- function(path) {
+ fileConn<- file(file.path(path, "backup_info.md"))
+ lines <- c(
+ "This is a backup of the actual project directory. ",
+ "",
+ "DO NOT EDIT THIS DIRECTORY.",
+ "",
+ "If you do, changes may be overwritten by future backups.",
+ "",
+ paste0("This directory was last backed up at ", Sys.time()),
+ ""
+ )
+ writeLines(lines, fileConn)
+ close(fileConn)
+}
+
+
+
+#' Open Project
+#' This function sets up the project to work on so the paths can easily be determined.
+#' When both paths are specified path functions will reference the local copy.
+#' When one is specified path functions will reference the local or remote copy whichever was specified.
+#' Future updates will add some functionality to automate tasks.
+#'
+#' @param local_project_folder This is a local copy of the project folder
+#' @param remote_project_folder This is the location of the shared drive copy of the project folder
+#'
+#' @export
+open_project <- function(local_project_folder="",remote_project_folder=""){
+ options(cida_tools.current_project_path = local_project_folder)
+ options(cida_tools.remote_current_project_path = remote_project_folder)
+}
+
+
+
+
+
diff --git a/R/project_internal.R b/R/project_internal.R
new file mode 100644
index 0000000..c719a63
--- /dev/null
+++ b/R/project_internal.R
@@ -0,0 +1,180 @@
+#'
+#' get_default_path() - checks the current project remote path first then
+#' project metadata file then checks user path file to return a default path to
+#' the CIDA Drive if no path was found automatically.
+#'
+#' @return path of project(CIDA) drive
+#' @noRd
+#' @noMd
+#'
+#'
+
+get_default_path <- function(){
+ path <- ""
+ ## TODO. Check project and then check User/Global Default
+
+ if(! is.null(options("cida_tools.remote_current_project_path")) && options("cida_tools.remote_current_project_path")!=""){
+ tmpPath=as.character(options("cida_tools.remote_current_project_path"))
+ if(fs::dir_exists(tmpPath)){
+ path <- tmpPath
+ # TODO: Fix this
+ path <- sub("BRANCHES.*","",path)
+ }
+ }
+
+ if(is.null(path) || path==""){
+ # Attempt to load project meta data and pull the path from it.
+ project_location=get_full_project_path()
+ project_dir=get_project_location()
+
+
+ if( (! is.null(project_location)&& project_location!="") && (! is.null(project_dir) && project_dir!="")){
+ path <- find_drive_location(project_location,project_dir)
+ }else if(! is.null(project_location)){
+ path <- project_location
+ }#else if(! is.null(project_dir)){
+ #}
+ }
+
+ if(is.null(path) || path==""){
+ #Attempt to load the global default path
+ path <- get_global_default_path()
+ }
+
+ if(is.null(path) || path==""){
+ warning("Failed to load project or global defaul location.")
+ }
+ return(path)
+}
+
+
+#' Internal Function to return Project Data path for use in the other methods
+#' that read .ProjData/Data.dcf. If options for the local/remote path are specified
+#' they will supersede the current directory upwards traversal to find .ProjData.
+#' If the paths are empty the normal traversal will be used that will fail after 3 parent
+#' directories.
+#'
+#' @noMd
+#' @noRd
+#'
+get_project_data_dir <- function(){
+ path <- ""
+
+ if(!is.null(options("cida_tools.current_project_path")) && options("cida_tools.current_project_path") !=""){
+ tmpPath <- fs::path(options("cida_tools.current_project_path"))
+ checkSuffix <- fs::path_join(c(tmpPath,'.ProjData/'))
+ if(fs::dir_exists(checkSuffix)){
+ path <- checkSuffix
+ }
+ }else if(!is.null(options("cida_tools.remote_current_project_path")) && options("cida_tools.remote_current_project_path") !=""){
+ tmpPath <- as.character(options("cida_tools.remote_current_project_path"))
+ checkSuffix <- fs::path_join(c(tmpPath,'.ProjData/'))
+ if(fs::dir_exists(checkSuffix)){
+ path <- checkSuffix
+ }
+ }
+
+ if(path==""){
+ ## TODO There should be a way to find the top project directory and not use
+ # the ../ relative navigation below that will fail after 3 subfolders.
+ if(fs::dir_exists('.ProjData/')){
+ path <- '.ProjData/'
+ }else if(fs::dir_exists('../.ProjData/')){
+ path <- '../.ProjData/'
+ }else if(fs::dir_exists('../../.ProjData/')){
+ path <- '../../.ProjData/'
+ }else if(fs::dir_exists('../../../.ProjData/')){
+ path <- '../../../.ProjData/'
+ }else{
+ warning(".ProjData directory not found in project.",call.=FALSE,immediate. = TRUE)
+ path <- '.ProjData/'
+ }
+ }
+
+ return(fs::path(path))
+}
+
+
+
+#' Internal Function to return Project Data path for use in the other methods
+#' that read .ProjData/Data.dcf
+#'
+#' @noMd
+#' @noRd
+#'
+get_project_data_path <- function(){
+ path <- get_project_data_dir()
+ path <- fs::path_join(c(path,"Data.dcf"))
+ return(path)
+}
+
+
+#' Internal Function to save Project Data for use in the other methods
+#' that update values in .ProjData/Data.dcf
+#'
+#' @noMd
+#' @noRd
+#'
+save_project_data <- function(project_metadata){
+ to_save <- NULL
+ path <- get_project_data_dir()
+ print(paste("Path",path))
+
+ current_meta_data <- get_project_meta_data()
+ if(!is.null(path)){
+ directory=fs::path_dir(path )
+ if(!fs::dir_exists(directory)){
+ fs::dir_create(path, recursive = TRUE, showWarnings = F)
+ }
+ }
+
+ if(!is.null(current_meta_data) ){
+ to_save <- current_meta_data
+ for (element in names(project_metadata)) {
+ to_save[element]=project_metadata[element]
+ }
+ }else{
+ to_save <- project_metadata
+ }
+ dcfFile <- paste(path,"/Data.dcf", sep="")
+ write_project_data(to_save,dcfFile)
+}
+
+
+#' Internal Function to write Project Data .ProjData/Data.dcf
+#'
+#' @param project_metadata project metadata to save
+#' @param path path to save the data to.
+#'
+#' @noMd
+#' @noRd
+#'
+write_project_data <- function(project_metadata,path){
+ write.dcf(project_metadata, fs::path(path))
+ return(TRUE)
+}
+
+
+#' helper function to cleanup project location
+#' @param loc project location path to clean up
+#' @noMd
+#' @noRd
+#'
+proj_location_handler <- function(loc="") {
+ loc <- gsub("/Volumes/sph-cida", "", loc)
+ loc <- gsub("P:/", "", loc)
+ loc <- gsub(".*BRANCHES", "BRANCHES", loc)
+ loc <- gsub("/$", "", loc)
+ return(loc)
+}
+
+
+#' Function to call to setup the package
+#'
+#'
+#' @noMd
+#' @noRd
+.onLoad <- function(libname,pkgname){
+ options(cida_tools.current_project_path="")
+ options(cida_tools.remote_current_project_path="")
+}
diff --git a/R/project_meta_data.R b/R/project_meta_data.R
index 98c8702..a204183 100644
--- a/R/project_meta_data.R
+++ b/R/project_meta_data.R
@@ -3,19 +3,15 @@
#' This function allows you to set the project analyst.
#' This will overwrite the current value if exists.
#'
-#' @param AnalystName A string containing the analyst name
+#' @param analyst_name A string containing the analyst name
#' @return A message stating the name has been changed.
#' @keywords options Analyst ProjData
#' @export
#'
-SetProjectAnalyst <- function(AnalystName){
- if(!is.character(AnalystName)) stop('Analyst Name must be a character string')
- if(length(AnalystName) > 1) {
- warning('Only First String is Used')
- AnalystName <- AnalystName[1]
- }
- SetProjectData('analyst', AnalystName)
- return(paste('The Project Analyst name has been changed to', AnalystName))
+set_project_analyst <- function(analyst_name){
+ analyst_name <- check_string_param_value(analyst_name,'analyst_name')
+ set_project_meta_data('analyst', analyst_name)
+ return(paste('The Project Analyst Name has been changed to', analyst_name))
}
#' Set Project Name
@@ -23,19 +19,15 @@ SetProjectAnalyst <- function(AnalystName){
#' This function allows you to set the project name. This will overwrite the
#' current value if exists.
#'
-#' @param ProjectName A string containing the analyst name
+#' @param project_name A string containing the analyst name
#' @return A message stating the name has been changed.
#' @keywords options ProjectName ProjData
#' @export
#'
-SetProjectName <- function(ProjectName){
- if(!is.character(ProjectName)) stop('Project Name must be a character string')
- if(length(ProjectName) > 1) {
- warning('Only First String is Used')
- ProjectName <- ProjectName[1]
- }
- SetProjectData('ProjectName', ProjectName)
- return(paste('The Project name has been changed to', ProjectName))
+set_project_name <- function(project_name){
+ project_name <- check_string_param_value(project_name,'project_name')
+ set_project_meta_data('ProjectName', project_name)
+ return(paste('The project name has been changed to', project_name))
}
#' Set PI Name
@@ -43,19 +35,15 @@ SetProjectName <- function(ProjectName){
#' This function allows you to set the Project's PI. This will overwrite the
#' current value if exists.
#'
-#' @param PI A string containing the analyst name
+#' @param pi A string containing the analyst name
#' @return A message stating the name has been changed.
#' @keywords options PI ProjData
#' @export
#'
-SetProjectPI <- function(PI){
- if(!is.character(PI)) stop('PI Name must be a character string')
- if(length(PI) > 1) {
- warning('Only First String is Used')
- PI <- PI[1]
- }
- SetProjectData('PI', PI)
- return(paste('The Project PI has been changed to', PI))
+set_project_pi <- function(pi){
+ pi <- check_string_param_value(pi,'PI')
+ set_project_meta_data('PI', pi)
+ return(paste('The Project PI has been changed to', pi))
}
#' Set Project Location
@@ -68,17 +56,43 @@ SetProjectPI <- function(PI){
#' @keywords options location ProjData
#' @export
#'
-SetProjectLocation <- function(path){
- if(!is.character(path)) stop('Path must be a character string')
- if(length(path) > 1) {
- warning('Only First String is Used')
- path <- path[1]
- }
- path <- proj.location.handler(path)
- SetProjectData('datalocation', path)
+set_project_location <- function(path){
+ path <- check_string_param_value(path,'path')
+ path <- proj_location_handler(path)
+ set_project_meta_data('datalocation', path)
return(paste('The Project Location has been changed to', path))
}
+#' Set Project GitHub Location
+#'
+#' This function allows you to set the Project's GitHub location.
+#' This will overwrite the current value if exists.
+#'
+#' @param git_url A string containing the URL to the GitHub repository for this project.
+#' @return A message stating the name has been changed.
+#' @keywords options location ProjData
+#' @export
+#'
+set_project_github <- function(git_url=''){
+ git_url <- check_string_param_value(git_url,'git_url')
+ set_project_meta_data('gitlocation', git_url)
+ return(paste('The Project GitHub Location has been changed to', git_url))
+}
+
+#' Get Project GitHub Location
+#'
+#' This function returns the Project GitHub location or blank if it's not set.
+#'
+#' @return A character string with the project GitHub
+#' @keywords options ProjData ProjectGitHub
+#' @export
+#'
+
+get_project_github <- function(){
+ git_url <- get_project_meta_data('gitlocation')
+ return(git_url)
+}
+
#' Get Project Analyst
#'
#' This function returns the Project Analyst Name. If none exists, it
@@ -90,23 +104,12 @@ SetProjectLocation <- function(path){
#' @export
#'
-ProjectAnalyst <- function(){
- if(file.exists(file.path('.ProjData/Data.dcf'))){
- ProjData <- read.dcf(file.path('.ProjData/Data.dcf'), all = T)
- if('analyst' %in% names(ProjData)) return(ProjData$analyst)
- }
- if(file.exists(file.path('../.ProjData/Data.dcf'))){
- ProjData <- read.dcf(file.path('../.ProjData/Data.dcf'), all = T)
- if('analyst' %in% names(ProjData)) return(ProjData$analyst)
+get_project_analyst <- function(){
+ analyst <- get_project_meta_data('analyst')
+ if(analyst==""){
+ analyst <- getOption('CIDAtools.analyst', default="")
}
- if(file.exists(file.path('../../.ProjData/Data.dcf'))){
- ProjData <- read.dcf(file.path('../../.ProjData/Data.dcf'), all = T)
- if('analyst' %in% names(ProjData)) return(ProjData$analyst)
- }
- if(!is.null(getOption('CIDAtools.analyst'))){
- return(getOption('CIDAtools.analyst'))
- }
- return('')
+ return(analyst)
}
#' Get Project Name
@@ -118,21 +121,9 @@ ProjectAnalyst <- function(){
#' @export
#'
-ProjectName <- function(){
- if(file.exists(file.path('.ProjData/Data.dcf'))){
- ProjData <- read.dcf(file.path('.ProjData/Data.dcf'), all = T)
- if('ProjectName' %in% names(ProjData)) return(ProjData$ProjectName)
- }
-
- if(file.exists(file.path('../.ProjData/Data.dcf'))){
- ProjData <- read.dcf(file.path('../.ProjData/Data.dcf'), all = T)
- if('ProjectName' %in% names(ProjData)) return(ProjData$ProjectName)
- }
- if(file.exists(file.path('../../.ProjData/Data.dcf'))){
- ProjData <- read.dcf(file.path('../../.ProjData/Data.dcf'), all = T)
- if('ProjectName' %in% names(ProjData)) return(ProjData$ProjectName)
- }
- return('')
+get_project_name <- function(){
+ project_name <- get_project_meta_data('ProjectName')
+ return(project_name)
}
#' Get PI Name
@@ -144,22 +135,9 @@ ProjectName <- function(){
#' @export
#'
-ProjectPI <- function(){
- if(file.exists(file.path('.ProjData/Data.dcf'))){
- ProjData <- read.dcf(file.path('.ProjData/Data.dcf'), all = T)
- if('PI' %in% names(ProjData)) return(ProjData$PI)
- }
- if(file.exists(file.path('../.ProjData/Data.dcf'))){
- ProjData <- read.dcf(file.path('../.ProjData/Data.dcf'), all = T)
- if('PI' %in% names(ProjData)) return(ProjData$PI)
- }
- if(file.exists(file.path('../../.ProjData/Data.dcf'))){
- ProjData <- read.dcf(file.path('../../.ProjData/Data.dcf'), all = T)
- if('PI' %in% names(ProjData)) return(ProjData$PI)
- }
-
-
- return('')
+get_project_pi <- function(){
+ project_pi <- get_project_meta_data('PI')
+ return(project_pi)
}
#' Get Project data location on CIDA Drive
@@ -176,87 +154,145 @@ ProjectPI <- function(){
#' }
#'
-ProjectLocation <- function(path = ''){
-
- if(file.exists(file.path('.ProjData/Data.dcf'))){
- ProjData <- read.dcf(file.path('.ProjData/Data.dcf'), all = T)
- if('datalocation' %in% names(ProjData)){
- temp_path <- CIDA_drive_path(ProjData$datalocation)
- return(file.path(temp_path, path))
- }
+get_project_location <- function(path = ''){
+ temp_path <- get_project_meta_data('datalocation')
+ full_path <- fs::path("")
+ if( temp_path!="" ){
+ full_path <- fs::path_join(c(temp_path, path))
+ }else{
+ message('Project location not found, use set_project_meta_data("datalocation", x).')
}
+ return(full_path)
+}
- if(file.exists(file.path('../.ProjData/Data.dcf'))){
- ProjData <- read.dcf(file.path('../.ProjData/Data.dcf'), all = T)
- if('datalocation' %in% names(ProjData)){
- temp_path <- CIDA_drive_path(ProjData$datalocation)
- return(file.path(temp_path, path))
- }
- }
- if(file.exists(file.path('../../.ProjData/Data.dcf'))){
- ProjData <- read.dcf(file.path('../../.ProjData/Data.dcf'), all = T)
- if('datalocation' %in% names(ProjData)){
- temp_path <- CIDA_drive_path(ProjData$datalocation)
- return(file.path(temp_path, path))
- }
- }
- message('Project location not found, use SetProjectData("datalocation", x).')
- return("")
+#' Sets the default full path to the project.
+#'
+#' @param path full path to the project folder
+#'
+#' @return message indicating the path has been saved.
+#' @export
+#'
+#'
+set_full_project_path <- function(path=''){
+ path <- check_string_param_value(path,'default_full_path_to_project')
+ set_project_meta_data('default_full_path_to_project', path)
+ return(paste('The project default full path has been changed to', path))
+}
+
+#' Gets the currently set full path to the project from .ProjData/Data.dcf
+#'
+#' @return full path to project
+#' @export
+#'
+get_full_project_path <- function(){
+ project_path <- get_project_meta_data('default_full_path_to_project')
+ return(project_path)
}
+
#' Set data for project
#'
#' Allows you to set misc project data parameters
#' for Project Name, Analyst, or PI recommend you use specific function
#'
-#' @param Parameter Project Parameter to be set
-#' @param Value Value to set to project parameter
+#'
+#' @param parameter Project Parameter to be set
+#' @param value Value to set to project parameter
#' @export
#'
#'
-SetProjectData <- function(Parameter, Value){
- if (!is.character(Parameter) | !is.character(Parameter))
- stop('Parameter must be a character string of length one')
- if(!is.character(Value)) stop('Value must be a character string')
- if(length(Value) > 1) {
- warning('Only First String is Used')
- Value <- Value[1]
+set_project_meta_data <- function(parameter, value){
+ parameter <- check_string_param_value(parameter,'parameter')
+ value <- check_string_param_value(value,'value')
+ if(parameter=='datalocation'){
+ value <- proj_location_handler(value)
}
- if(Parameter=='datalocation'){
- Value <- proj.location.handler(Value)
- }
- if(file.exists(file.path('.ProjData/Data.dcf'))){
- ProjData <- read.dcf(file.path('.ProjData/Data.dcf'), all = T)
- } else{
- dir.create(paste0('.ProjData/'), recursive = T, showWarnings = F)
- ProjData <- list()
+
+ proj_data <- get_full_project_data()
+
+ if(parameter %in% names(proj_data)){
+ proj_data[parameter] <- value
+ }else{
+ proj_data[parameter] <- value
}
- ProjData[Parameter] <- Value
- write.dcf(ProjData, file.path('.ProjData/Data.dcf'))
+
+ save_project_data(proj_data)
}
#' Get data for project
#'
-#' Allows you to get misc project data parameters
+#' Allows you to get any project data parameters or all parameters. Either specify
+#' the desired parameter or with no parameter it will return all available parameters.
+#'
+#' Possible parameters values include:
+#'
+#' - analyst - Analyst's Name
+#'
+#' - ProjectName - Project Name
+#'
+#' - PI - PI Name
+#'
+#' - datalocation - Poject folder location under the CIDA PATH.
+#'
+#' - default_full_path_to_project - Project default path which is the default full path to the project files. Includes the local filesystem path to network mount point and network path to project folder.
#'
-#' @param param Project parameter to be gotten
+#' - gitlocation - GitHub URL for the project code
+#'
+#'
+#' @param param Project parameter to return or if not specified to return all parameter/value pairs.
#' @export
#'
-getProjectData <- function(param){
- if(file.exists(file.path('.ProjData/Data.dcf'))){
- ProjData <- read.dcf(file.path('.ProjData/Data.dcf'), all = T)
- if(param %in% names(ProjData)) return(ProjData[[param]])
- }
- if(file.exists(file.path('../.ProjData/Data.dcf'))){
- ProjData <- read.dcf(file.path('../.ProjData/Data.dcf'), all = T)
- if(param %in% names(ProjData)) return(ProjData[[param]])
- }
- if(file.exists(file.path('../../.ProjData/Data.dcf'))){
- ProjData <- read.dcf(file.path('../../.ProjData/Data.dcf'), all = T)
- if(param %in% names(ProjData)) return(ProjData[[param]])
+get_project_meta_data <- function(param=''){
+ value <- ''
+ project_data <- get_full_project_data()
+ if(is.null(param) || param==''){
+
+ value <- project_data
+
+ }else if( !is.null(project_data)){
+ #value <- project_data
+ if(param %in% names(project_data)){
+ value <- project_data[[param]]
+ }else{
+ warning(paste(c(param," not found in project data.")),call.=FALSE,immediate. = TRUE)
+ }
+ }else{
+ warning(paste(c("get_project_meta_data(",param,") returned NULL project data.")),call.=FALSE,immediate. = TRUE)
}
- return('')
+
+ return(value)
+
+}
+
+
+#' Internal Function to return Project Data object for use in the other methods
+#' that read .ProjData/Data.dcf
+#'
+#' @noMd
+#' @noRd
+#'
+
+get_full_project_data <- function(){
+ proj_data <- NULL
+ path <- get_project_data_path()
+ if(is.null(path) || path == "" ){
+ warning(".ProjData/Data.dcf file not found in project.",call.=FALSE,immediate. = TRUE)
+ }else if(path !=""){
+ #print(paste0("ERROR:",path,"::"))
+ if(fs::file_exists(path) && fs::file_size(path)>0 ){
+ proj_data <- read.dcf(file.path(path), all = T)
+ }else if(fs::file_exists(path) && fs::file_size(path)==0){
+ warning(paste(path," File is empty.",sep=""))
+ }else if(! fs::file_exists(path) ){
+ warning(paste(path," File does not exist.",sep=""))
+ }
+ }
+ return(proj_data)
}
+
+
+
+
diff --git a/R/randomizer_and_blinder_app.R b/R/randomizer_and_blinder_app.R
index fd75e0e..5aa8d88 100755
--- a/R/randomizer_and_blinder_app.R
+++ b/R/randomizer_and_blinder_app.R
@@ -1,9 +1,11 @@
-#' Randomizer and blinder tool
+#' Randomizer and blinder tool - To be deprecated
#'
#' See the inst/ folder for the main code for this function
#'
#' @export
randblinder_shiny_tool <- function() {
+ deprecation_warn("randomizer_and_blinder_app.randblinder_shiny_tool")
+
appFile <- system.file("shiny_app/randblinder.R", package = "CIDAtools")
if (appFile == "") {
stop("Could not find the Shiny app file. Try re-installing CIDAtools.", call. = FALSE)
diff --git a/R/read_xlsx_color.R b/R/read_xlsx_color.R
index 03128d9..a710a29 100644
--- a/R/read_xlsx_color.R
+++ b/R/read_xlsx_color.R
@@ -1,4 +1,4 @@
-#' Read in xlsx with fill colour
+#' Read in xlsx with fill colour - To be deprecated
#'
#' Reads in the fill colour of excel workbooks. Creates a data frame for each
#' sheet in a list if mutliple sheets are requested. Creates a colour column for
@@ -23,6 +23,9 @@
#' @keywords Excel colour color xlsx
#'
read_xlsx_color <- function(file, colorColumns, sheet = NULL, header = T){
+
+ deprecation_warn("read_xlsx_color.read_xlsx_color")
+
if(!requireNamespace("xlsx", quietly = TRUE))
stop("package 'xlsx' is required.")
if(!is.list(colorColumns) & is.numeric(colorColumns))
diff --git a/R/reporting_fns.R b/R/reporting_fns.R
index 8caa498..1542a54 100644
--- a/R/reporting_fns.R
+++ b/R/reporting_fns.R
@@ -1,4 +1,4 @@
-#' Pretty p-values
+#' Pretty p-values - To be deprecated
#'
#' This function helps print p-values in RMD output
#'
@@ -12,7 +12,7 @@
#' @export
#'
pvalr <- function(pvals, sig.limit = .001, digits = 3, html = FALSE, equal_sign = "") {
-
+ deprecation_warn("reporting_fns.pvalr")
roundr <- function(x, digits = 1) {
res <- sprintf(paste0('%.', digits, 'f'), x)
zzz <- paste0('0.', paste(rep('0', digits), collapse = ''))
@@ -34,7 +34,7 @@ pvalr <- function(pvals, sig.limit = .001, digits = 3, html = FALSE, equal_sign
}, sig.limit = sig.limit)
}
-#' List tables with the same columns
+#' List tables with the same columns - To be deprecated
#'
#' This function will print a group of tables together in a decently pretty way.
#' May need a bit of finagling.
@@ -48,7 +48,7 @@ pvalr <- function(pvals, sig.limit = .001, digits = 3, html = FALSE, equal_sign
#' @export
list_kables <- function(tabs, bo = c("striped", "condensed"), ...) {
-
+ deprecation_warn("reporting_fns.list_kables")
idx <- sapply(tabs, nrow)
tabs %>%
diff --git a/R/temp_refactored_message.R b/R/temp_refactored_message.R
new file mode 100644
index 0000000..94257c0
--- /dev/null
+++ b/R/temp_refactored_message.R
@@ -0,0 +1,121 @@
+# Functions to warn users of refactored methods and provide the renamed function.
+# These are expected to be short term/temporary functions to aid in transition
+# after refactoring to provide consistent naming across the package.
+# Perhaps remove following deprecation of the methods marked for deprecation.
+
+
+#' @inherit get_project_drive_path
+#' @export
+CIDA_drive_path <- function(file="") {
+ renamed_warn(function_name="CIDA_drive_path", replacement_name="get_project_drive_path")
+ #warning( paste(c("CIDA_drive_path() renamed to get_project_drive_path()")),immediate. = TRUE)
+ return(get_project_drive_path(file))
+}
+
+
+#' @inherit set_project_name
+#' @export
+SetProjectName <- function(project_name){
+ renamed_warn(function_name="SetProjectName", replacement_name="set_project_name")
+ #warning( paste(c("SetProjectName(ProjectName) renamed to set_project_name(project_name)")),immediate. = TRUE)
+ return(set_project_name(project_name))
+}
+
+#' @inherit set_project_analyst
+#' @export
+SetProjectAnalyst <- function(analyst_name){
+ renamed_warn(function_name="SetProjectAnalyst", replacement_name="set_project_analyst")
+ #warning( paste(c("SetProjectAnalyst() renamed to set_project_analyst()")),immediate. = TRUE)
+ return(set_project_analyst(analyst_name))
+}
+
+
+#' @inherit set_project_pi
+#' @export
+SetProjectPI <- function(pi){
+ renamed_warn(function_name="SetProjectPI", replacement_name="set_project_pi")
+ #warning( paste(c("SetProjectPI() renamed to set_project_pi()")),immediate. = TRUE)
+ return(set_project_pi(pi))
+}
+
+
+#' @inherit set_project_location
+#' @export
+SetProjectLocation <- function(path){
+ renamed_warn(function_name="SetProjectLocation", replacement_name="set_project_location")
+ #warning( paste(c("SetProjectLocation() renamed to set_project_location()")),immediate. = TRUE)
+ return(set_project_location(path))
+}
+
+#' @inherit get_project_analyst
+#' @export
+ProjectAnalyst <- function(){
+ renamed_warn(function_name="ProjectAnalyst", replacement_name="get_project_analyst")
+ #warning( paste(c("ProjectAnalyst() renamed to get_project_analyst()")),immediate. = TRUE)
+ return(get_project_analyst())
+}
+
+#' @inherit get_project_name
+#' @export
+ProjectName <- function(){
+ renamed_warn(function_name="ProjectName", replacement_name="get_project_name")
+ #warning( paste(c("ProjectName() renamed to get_project_name()")),immediate. = TRUE)
+ return(get_project_name())
+}
+
+#' @inherit get_project_pi
+#' @export
+ProjectPI <- function(){
+ renamed_warn(function_name="ProjectPI", replacement_name="get_project_pi")
+ #warning( paste(c("ProjectPI() renamed to get_project_pi()")),immediate. = TRUE)
+ return(get_project_pi())
+}
+
+#' @inherit get_project_location
+#' @export
+ProjectLocation <- function(){
+ renamed_warn(function_name="ProjectLocation", replacement_name="get_project_location")
+ #warning( paste(c("ProjectLocation() renamed to get_project_location()")),immediate. = TRUE)
+ return(get_project_location())
+}
+
+#' @inherit set_project_meta_data
+#' @export
+SetProjectData <- function(parameter,value){
+ renamed_warn(function_name="SetProjectData", replacement_name="set_project_meta_data")
+ #warning( paste(c("SetProjectData() renamed to set_project_meta_data()")),immediate. = TRUE)
+ set_project_meta_data(parameter,value)
+}
+
+#' @inherit get_project_meta_data
+#' @export
+getProjectData <- function(param){
+ renamed_warn(function_name="getProjectData", replacement_name="get_project_meta_data")
+ #warning( paste(c("getProjectData() renamed to get_project_meta_data()")),immediate. = TRUE)
+ return(get_project_meta_data(param))
+}
+
+#' @inherit set_project_analyst
+#' @export
+setAnalyst <- function(analyst_name){
+ renamed_warn(function_name="setAnalyst", replacement_name="set_project_analyst")
+ #warning( paste(c("setAnalyst() renamed to set_project_analyst()")),immediate. = TRUE)
+ return(set_project_analyst(analyst_name))
+}
+
+#' @inherit set_global_default_analyst
+#' @export
+setPermanentAnalyst <- function(analyst_name, update_template=FALSE){
+ renamed_warn(function_name="setPermanentAnalyst", replacement_name="set_global_default_analyst")
+ #warning( paste(c("setPermanentAnalyst() renamed to set_global_default_analyst()")),immediate. = TRUE)
+ return(set_global_default_analyst(analyst_name, update_template))
+}
+
+
+#' @inherit remove_global_default_analyst
+#' @export
+removeAnalyst <- function(){
+ renamed_warn(function_name="removeAnalyst", replacement_name="remove_global_default_analyst")
+ warning( paste(c("removeAnalyst() renamed to remove_global_default_analyst()")),immediate. = TRUE)
+ return(remove_global_default_analyst())
+}
diff --git a/R/util_internal.R b/R/util_internal.R
new file mode 100644
index 0000000..38a72a9
--- /dev/null
+++ b/R/util_internal.R
@@ -0,0 +1,129 @@
+#' Internal Utility Functions
+
+#' Sets the contact email address.
+#'
+#'
+#'
+#' @return The email address to contact.
+#'
+#' @noRd
+#' @noMd
+#'
+warning_email <- function(){
+ email <- "cida-rt@olucdenver.onmicrosoft.com"
+ return(email)
+}
+
+#' Check String Parameter Values for errors
+#'
+#'
+#' @param value parameter value to check
+#' @return the value to be used after checking it is a character value and not an array or returning the first value of the array.
+#'
+#' @noRd
+#' @noMd
+#'
+check_string_param_value <- function(value="",parameter=""){
+
+ if(!is.character(value)) stop(parameter,' must be a character string')
+ if(length(value) > 1) {
+ warning('Only First String is Used')
+ value <- value[1]
+ }
+ return(value)
+}
+
+
+
+#' Find and return the beginning of the full path up to the start of the common path.
+#'
+#' @importFrom utils head
+#'
+#' @param full_path The full path to search for the partial path in.
+#' @param partial_path The partial path which may start any were in the full path.
+#' @return The beginning of the full path proceeding the start of the partial path.
+#'
+#' @noRd
+#' @noMd
+#'
+find_drive_location <- function(full_path="",partial_path=""){
+ parts_full<- fs::path_split(full_path)[[1]]
+ parts_partial <- fs::path_split(partial_path)[[1]]
+ common_index_start=1
+ if(parts_partial[common_index_start]=="/"){
+ common_index_start=2
+ }
+ match_index <- -1
+ for (i in seq_along(parts_full)){
+ if(parts_full[i]==parts_partial[common_index_start]){
+ oldI=i
+ is_match=TRUE
+ for (j in common_index_start:length(parts_partial)){
+ if(parts_partial[j] != parts_full[i]){
+ is_match=FALSE
+ break
+ }
+ i <- i+1
+ }
+ if(is_match){
+ match_index<-oldI-1
+ }
+ i=oldI
+ }
+ }
+
+ drive_parts <- head(parts_full,match_index)
+ drive_path <- fs::path_join(drive_parts)[[1]]
+ return(drive_path)
+}
+
+
+
+
+#' Deprecation Warning for functions flagged to be deprecated
+#' deprecation_warn() - print a warning that the function will be deprecated.
+#'
+#' @param function_name Function name the warning was called from.
+#'
+#' @noRd
+#' @noMd
+#'
+deprecation_warn <- function(function_name=""){
+ warning(paste(c(function_name,"() has been deprecated and will be removed in ",
+ "future package versions.\nPlease contact ",
+ warning_email(),
+ " if you regularly use this ",
+ "function\nand would like to see it stay.")),
+ call.=FALSE,immediate. = TRUE)
+}
+
+
+
+#' Deprecated Warning for functions already deprecated
+#'
+#' deprecated_warn() - function to call for deprecated functions listing the
+#' version that removed the function
+#'
+#' @param function_name Version of package function was removed.
+#' @param version Version of package function was removed.
+#'
+#' @noRd
+#' @noMd
+#'
+deprecated_warn <- function(function_name="", version=""){
+ warning(paste(c(function_name,"() was deprecated in version ",version)),call.=FALSE,immediate. = TRUE)
+}
+
+#' Deprecated Warning for renamed functions.
+#' renamed_warn() - Functon which notifies the user that the called function
+#' has been renamed.
+#'
+#' @param function_name The old function name.
+#' @param replacement_name The new function name.
+#' @noRd
+#' @noMd
+renamed_warn <- function(function_name="", replacement_name="") {
+ warning(paste(c(function_name, "() has been renamed to ", replacement_name, "(). Please use the updated function name in new code.")), call.=FALSE, immediate.=TRUE)
+}
+
+
diff --git a/README.md b/README.md
index 3c8ab6f..4df9b57 100644
--- a/README.md
+++ b/README.md
@@ -1,107 +1,147 @@
+# CIDATools
+
+
# CIDAtools
-[](https://github.com/CIDA-CSPH/CIDAtools/actions/workflows/R-CMD-check.yaml)
+
+
pak::pak("CIDA-CSPH/CIDAtools@v0.1.2")
## Creating a new project
-After `CIDAtools` is installed, a new CIDA project can be created using the
-Rstudio GUI (File>New Project>New Directory>New CIDA Project).
+After `CIDAtools` is installed, a new CIDA project can be created using
+the Rstudio GUI (File\>New Project\>New Directory\>New CIDA Project).
-Or, to create a new project folder structure from the R console,
-navigate to the main project directory, and run:
+Or, to create a new project folder structure from the R console,
+navigate to the main project directory, and run:
-```
-create_project()
-```
+ create_project(project_name="My Project",analyst = "Your Name")
-Feel free to set the project name, PI, and analyst via the `ProjectName`, `PI`, or `analyst`
-arguments respectively, and see `?create_project` for more details. If any of these are
-specified, they are stored as text in a hidden subdirectory called .ProjData, and can
-be called in subsequent R code anywhere in the project using `ProjectName()`, `ProjectPI()`, and
-`ProjectAnalyst()`.
+Feel free to set the project name, PI, and analyst via the
+`ProjectName`, `PI`, or `analyst` arguments respectively, and see
+`?create_project` for more details. If any of these are specified, they
+are stored as text in a hidden subdirectory called .ProjData, and can be
+called in subsequent R code anywhere in the project using
+`ProjectName()`, `ProjectPI()`, and `ProjectAnalyst()`.
## Creating a new CIDA report
-**Templates** are useful for creating new documents with the correct CIDA *formatting*.
-
-`CIDAtools` includes templates that can make it easy to create a new CIDA report.
-To use this functionality in Rstudio, first ensure the package is installed, then:
+**Templates** are useful for creating new documents with the correct
+CIDA *formatting*.
-1) Click on "New R Markdown"
-2) In the pop-up, select "From template"
-3) You should see CIDA report templates to choose from.
+`CIDAtools` includes templates that can make it easy to create a new
+CIDA report. To use this functionality in Rstudio, first ensure the
+package is installed, then:
-Alternatively, source code for templates is available in inst/rmarkdown/templates/.
+1. Click on “New R Markdown”
+2. In the pop-up, select “From template”
+3. You should see CIDA report templates to choose from.
-Note: the CIDA Word report template contains multiple files, which are needed to specify the format for Word output.
-Therefore, CIDA Word reports must have their own subdirectory to start.
+Alternatively, source code for templates is available in
+inst/rmarkdown/templates/.
+Note: the CIDA Word report template contains multiple files, which are
+needed to specify the format for Word output. Therefore, CIDA Word
+reports must have their own subdirectory to start.
## Outlines for CIDA reports
-**Outlines** are intended to provide an idea of the *content* necessary within each type of CIDA report.
-
-`CIDAtools` includes outlines for the following reports in inst/outlines/:
-
-- CIDA Analysis Plan [[download]](https://github.com/CIDA-CSPH/CIDAtools/raw/master/inst/outlines/CIDA-Analysis-Plan-Outline.docx)
-- CIDA Comprehensive Report [[download]](https://github.com/CIDA-CSPH/CIDAtools/raw/master/inst/outlines/CIDA-Comprehensive-Report-Outline.docx)
-- CIDA Exploratory Report [[download]](https://github.com/CIDA-CSPH/CIDAtools/raw/master/inst/outlines/CIDA-Exploratory-Report-Outline.docx)
-- CIDA Omics Study Report [[download]](https://github.com/CIDA-CSPH/CIDAtools/raw/master/inst/outlines/CIDA-Omics-Outline.docx)
-- CIDA Study Design [[download]](https://github.com/CIDA-CSPH/CIDAtools/raw/master/inst/outlines/CIDA-Study-Design-Outline.docx)
-
-## Backing up CIDA projects
-
-CIDA project data and reports should be either kept on the CIDA shared drive (the P drive), or backed up (i.e. copied) to the shared drive on a regular basis.
-
-Since the P drive can sometimes be slow to read/write on, CIDA members can work on a project locally if they regularly back up the project to the P drive. To help with this, we've written the function `backup_project` which will automatically back up a project folder to the P drive (to the "Projects" subdirectory by default, but this can be specified with the `subdir_to` argument). Alternatively, the main project folder can simply be copied and pasted to the P drive manually.
+**Outlines** are intended to provide an idea of the *content* necessary
+within each type of CIDA report.
+
+`CIDAtools` includes outlines for the following reports in
+inst/outlines/:
+
+- CIDA Analysis Plan
+ [\[download\]](https://github.com/CIDA-CSPH/CIDAtools/raw/master/inst/outlines/CIDA-Analysis-Plan-Outline.docx)
+- CIDA Comprehensive Report
+ [\[download\]](https://github.com/CIDA-CSPH/CIDAtools/raw/master/inst/outlines/CIDA-Comprehensive-Report-Outline.docx)
+- CIDA Exploratory Report
+ [\[download\]](https://github.com/CIDA-CSPH/CIDAtools/raw/master/inst/outlines/CIDA-Exploratory-Report-Outline.docx)
+- CIDA Omics Study Report
+ [\[download\]](https://github.com/CIDA-CSPH/CIDAtools/raw/master/inst/outlines/CIDA-Omics-Outline.docx)
+- CIDA Study Design
+ [\[download\]](https://github.com/CIDA-CSPH/CIDAtools/raw/master/inst/outlines/CIDA-Study-Design-Outline.docx)
+
+## Backing up CIDA projects
+
+CIDA project data and reports should be either kept on the CIDA shared
+drive (the P drive), or backed up (i.e. copied) to the shared drive on a
+regular basis.
+
+Since the P drive can sometimes be slow to read/write on, CIDA members
+can work on a project locally if they regularly back up the project to
+the P drive. To help with this, we’ve written the function
+`backup_project` which will automatically back up a project folder to
+the P drive (to the “Projects” subdirectory by default, but this can be
+specified with the `subdir_to` argument). Alternatively, the main
+project folder can simply be copied and pasted to the P drive manually.
Within a project directory, run:
-```
-backup_project()
-```
-This will copy over the entire local project (all files and directories) to a project of the same name in the P drive. A backup_info.md file will also be produced that indicates when the backup was performed.
+ backup_project()
+
+This will copy over the entire local project (all files and directories)
+to a project of the same name in the P drive. A backup_info.md file will
+also be produced that indicates when the backup was performed.
-If the project directory already exists in the P drive, only files/directories that have changed since the last backup will be copied over. This speeds up the process.
+If the project directory already exists in the P drive, only
+files/directories that have changed since the last backup will be copied
+over. This speeds up the process.
-Files located in the backup directory that are not in the project directory are not deleted. This means if you have large files, anytime you rename them and re-run the backup function, the storage needed will double since both files will remain in the backup folder. To avoid this, specify `recreate = TRUE` to fully recreate the current directory from the ground up.
+Files located in the backup directory that are not in the project
+directory are not deleted. This means if you have large files, anytime
+you rename them and re-run the backup function, the storage needed will
+double since both files will remain in the backup folder. To avoid this,
+specify `recreate = TRUE` to fully recreate the current directory from
+the ground up.
## Documentation
-The package website is available [here](https://cida-csph.github.io/CIDAtools).
-We plan to keep track of SAS macros and useful R packages in Article there (package vignettes).
+The package website is available
+[here](https://cida-csph.github.io/CIDAtools). We plan to keep track of
+SAS macros and useful R packages in Article there (package vignettes).
## Using snippets
-CIDA functions can be used in snippets (if you have a header snippet already in your Rstudio options):
+CIDA functions can be used in snippets (if you have a header snippet
+already in your Rstudio options):
Example of a header snippet using Project Data:
-```
-snippet header
- ###########################################
- # Project: `r CIDAtools::ProjectName()`
- # Author: `r CIDAtools::ProjectAnalyst()`
- # Date: `r paste(format(Sys.Date(), '%m/%d/%Y'))`
- # #########################################
-```
-## Other functionality
+ snippet header
+ ###########################################
+ # Project: `r CIDAtools::ProjectName()`
+ # Author: `r CIDAtools::ProjectAnalyst()`
+ # Date: `r paste(format(Sys.Date(), '%m/%d/%Y'))`
+ # #########################################
-This package also contains functions for reading excel files with color columns
-and the Table1 function.
+## Other functionality
-Please feel free to file an issue request if you encounter errors or would like
-to request new features. If reporting a bug, please provide a reproducible example.
+This package also contains functions for reading excel files with color
+columns and the Table1 function.
+Please feel free to file an issue request if you encounter errors or
+would like to request new features. If reporting a bug, please provide a
+reproducible example.
diff --git a/README.qmd b/README.qmd
new file mode 100644
index 0000000..f25f77d
--- /dev/null
+++ b/README.qmd
@@ -0,0 +1,114 @@
+---
+title: "CIDATools"
+format: html
+---
+
+# CIDAtools
+
+[](https://github.com/CIDA-CSPH/CIDAtools/actions/workflows/R-CMD-check.yaml)
+
+## Overview
+
+This package contains numerous templates and tools to make life at CIDA (part
+of the Colorado School of Public Health) happier and more efficient!
+
+To install `CIDAtools` on your local machine:
+
+```
+ # install.packages("pak")
+ pak::pak('CIDA-CSPH/CIDAtools')
+
+```
+
+## Creating a new project
+
+After `CIDAtools` is installed, a new CIDA project can be created using the
+Rstudio GUI (File>New Project>New Directory>New CIDA Project).
+
+Or, to create a new project folder structure from the R console,
+navigate to the main project directory, and run:
+
+```
+create_project(project_name="My Project",analyst = "Your Name")
+```
+
+Feel free to set the project name, PI, and analyst via the `ProjectName`, `PI`, or `analyst`
+arguments respectively, and see `?create_project` for more details. If any of these are
+specified, they are stored as text in a hidden subdirectory called .ProjData, and can
+be called in subsequent R code anywhere in the project using `ProjectName()`, `ProjectPI()`, and
+`ProjectAnalyst()`.
+
+## Creating a new CIDA report
+
+**Templates** are useful for creating new documents with the correct CIDA *formatting*.
+
+`CIDAtools` includes templates that can make it easy to create a new CIDA report.
+To use this functionality in Rstudio, first ensure the package is installed, then:
+
+1) Click on "New R Markdown"
+2) In the pop-up, select "From template"
+3) You should see CIDA report templates to choose from.
+
+Alternatively, source code for templates is available in inst/rmarkdown/templates/.
+
+Note: the CIDA Word report template contains multiple files, which are needed to specify the format for Word output.
+Therefore, CIDA Word reports must have their own subdirectory to start.
+
+
+## Outlines for CIDA reports
+
+**Outlines** are intended to provide an idea of the *content* necessary within each type of CIDA report.
+
+`CIDAtools` includes outlines for the following reports in inst/outlines/:
+
+- CIDA Analysis Plan [[download]](https://github.com/CIDA-CSPH/CIDAtools/raw/master/inst/outlines/CIDA-Analysis-Plan-Outline.docx)
+- CIDA Comprehensive Report [[download]](https://github.com/CIDA-CSPH/CIDAtools/raw/master/inst/outlines/CIDA-Comprehensive-Report-Outline.docx)
+- CIDA Exploratory Report [[download]](https://github.com/CIDA-CSPH/CIDAtools/raw/master/inst/outlines/CIDA-Exploratory-Report-Outline.docx)
+- CIDA Omics Study Report [[download]](https://github.com/CIDA-CSPH/CIDAtools/raw/master/inst/outlines/CIDA-Omics-Outline.docx)
+- CIDA Study Design [[download]](https://github.com/CIDA-CSPH/CIDAtools/raw/master/inst/outlines/CIDA-Study-Design-Outline.docx)
+
+## Backing up CIDA projects
+
+CIDA project data and reports should be either kept on the CIDA shared drive (the P drive), or backed up (i.e. copied) to the shared drive on a regular basis.
+
+Since the P drive can sometimes be slow to read/write on, CIDA members can work on a project locally if they regularly back up the project to the P drive. To help with this, we've written the function `backup_project` which will automatically back up a project folder to the P drive (to the "Projects" subdirectory by default, but this can be specified with the `subdir_to` argument). Alternatively, the main project folder can simply be copied and pasted to the P drive manually.
+
+Within a project directory, run:
+```
+backup_project()
+```
+
+This will copy over the entire local project (all files and directories) to a project of the same name in the P drive. A backup_info.md file will also be produced that indicates when the backup was performed.
+
+If the project directory already exists in the P drive, only files/directories that have changed since the last backup will be copied over. This speeds up the process.
+
+Files located in the backup directory that are not in the project directory are not deleted. This means if you have large files, anytime you rename them and re-run the backup function, the storage needed will double since both files will remain in the backup folder. To avoid this, specify `recreate = TRUE` to fully recreate the current directory from the ground up.
+
+## Documentation
+
+The package website is available [here](https://cida-csph.github.io/CIDAtools).
+We plan to keep track of SAS macros and useful R packages in Article there (package vignettes).
+
+## Using snippets
+
+CIDA functions can be used in snippets (if you have a header snippet already in your Rstudio options):
+
+Example of a header snippet using Project Data:
+```
+snippet header
+ ###########################################
+ # Project: `r CIDAtools::ProjectName()`
+ # Author: `r CIDAtools::ProjectAnalyst()`
+ # Date: `r paste(format(Sys.Date(), '%m/%d/%Y'))`
+ # #########################################
+```
+
+## Other functionality
+
+This package also contains functions for reading excel files with color columns
+and the Table1 function.
+
+Please feel free to file an issue request if you encounter errors or would like
+to request new features. If reporting a bug, please provide a reproducible example.
+
+
diff --git a/_pkgdown.yml b/_pkgdown.yml
deleted file mode 100644
index 0cbb31a..0000000
--- a/_pkgdown.yml
+++ /dev/null
@@ -1,4 +0,0 @@
-url: https://cida-csph.github.io/CIDAtools/
-template:
- bootstrap: 5
-
diff --git a/altdoc/pkgdown.yml b/altdoc/pkgdown.yml
new file mode 100644
index 0000000..de8ee21
--- /dev/null
+++ b/altdoc/pkgdown.yml
@@ -0,0 +1,4 @@
+urls:
+ reference: https:/cida-csph.github.io/CIDAtools/man
+ article: https:/cida-csph.github.io/CIDAtools/vignettes
+
diff --git a/altdoc/quarto_website.yml b/altdoc/quarto_website.yml
new file mode 100644
index 0000000..66e7828
--- /dev/null
+++ b/altdoc/quarto_website.yml
@@ -0,0 +1,42 @@
+project:
+ type: website
+ output-dir: ../website
+
+# Note: freeze functionality can be set at a project level or for individual .qmd files
+# execute:
+# freeze: false
+
+website:
+ title: "$ALTDOC_PACKAGE_NAME"
+ code-links: true
+ navbar:
+ search: true
+ right:
+ - icon: github
+ href: $ALTDOC_PACKAGE_URL_GITHUB
+ aria-label: $ALTDOC_PACKAGE_NAME GitHub
+ sidebar:
+ collapse-level: 1
+ contents:
+ - text: Home
+ file: index.qmd
+ - section: $ALTDOC_VIGNETTE_BLOCK
+ - section: $ALTDOC_MAN_BLOCK
+ - text: News
+ file: $ALTDOC_NEWS
+ - text: Changelog
+ file: $ALTDOC_CHANGELOG
+ - text: License
+ file: $ALTDOC_LICENSE
+ - text: Licence
+ file: $ALTDOC_LICENCE
+ - text: Code of conduct
+ file: $ALTDOC_CODE_OF_CONDUCT
+ - text: Citation
+ file: $ALTDOC_CITATION
+
+format:
+ html:
+ code-link: true
+# theme: cosmo
+# number-sections: false
diff --git a/inst/rmarkdown/templates/data_dict_html/skeleton/skeleton.Rmd b/inst/rmarkdown/templates/data_dict_html/skeleton/skeleton.Rmd
index 805a048..70f836a 100644
--- a/inst/rmarkdown/templates/data_dict_html/skeleton/skeleton.Rmd
+++ b/inst/rmarkdown/templates/data_dict_html/skeleton/skeleton.Rmd
@@ -1,9 +1,9 @@
---
title: "Data Dictionary"
author: |
- | Project: `r CIDAtools::ProjectName()`
- | Analyst: `r CIDAtools::ProjectAnalyst()`
- | Investigator(s): `r CIDAtools::ProjectPI()`
+ | Project: `r CIDAtools::get_project_name()`
+ | Analyst: `r CIDAtools::get_project_analyst()`
+ | Investigator(s): `r CIDAtools::get_project_pi()`
| Date generated: `r paste(format(Sys.Date(), '%B %d, %Y'))`
output:
html_document:
diff --git a/inst/rmarkdown/templates/report_html/skeleton/skeleton.Rmd b/inst/rmarkdown/templates/report_html/skeleton/skeleton.Rmd
index b029dcd..6dbcc97 100755
--- a/inst/rmarkdown/templates/report_html/skeleton/skeleton.Rmd
+++ b/inst/rmarkdown/templates/report_html/skeleton/skeleton.Rmd
@@ -1,11 +1,11 @@
---
title: Report
author: |
- | Project: `r CIDAtools::ProjectName()`
+ | Project: `r CIDAtools::get_project_name()`
|
- | Analyst: `r CIDAtools::ProjectAnalyst()`
+ | Analyst: `r CIDAtools::get_project_analyst()`
|
- | Investigator(s): `r CIDAtools::ProjectPI()`
+ | Investigator(s): `r CIDAtools::get_project_pi()`
|
| Report generated: `r paste(format(Sys.Date(), '%B %d, %Y'))`
output:
diff --git a/inst/rmarkdown/templates/report_pdf/skeleton/skeleton.Rmd b/inst/rmarkdown/templates/report_pdf/skeleton/skeleton.Rmd
index 95ed1d1..7276b44 100755
--- a/inst/rmarkdown/templates/report_pdf/skeleton/skeleton.Rmd
+++ b/inst/rmarkdown/templates/report_pdf/skeleton/skeleton.Rmd
@@ -34,9 +34,9 @@ library(kableExtra)
library(CIDAtools)
```
-**Project**: `r CIDAtools::ProjectName()` \newline
-**Analyst**: `r CIDAtools::ProjectAnalyst()`\newline
-**Investigator(s)**: `r CIDAtools::ProjectPI()`\newline
+**Project**: `r CIDAtools::get_project_name()` \newline
+**Analyst**: `r CIDAtools::get_project_analyst()`\newline
+**Investigator(s)**: `r CIDAtools::get_project_pi()`\newline
**Report generated**: `r paste(format(Sys.Date(), '%B %d, %Y'))`\newline
diff --git a/man/CIDA_drive_path.Rd b/man/CIDA_drive_path.Rd
index a4d2253..0f2f987 100644
--- a/man/CIDA_drive_path.Rd
+++ b/man/CIDA_drive_path.Rd
@@ -1,25 +1,34 @@
% Generated by roxygen2: do not edit by hand
-% Please edit documentation in R/cida_drive_path.R
+% Please edit documentation in R/temp_refactored_message.R
\name{CIDA_drive_path}
\alias{CIDA_drive_path}
-\title{Get CIDA drive path}
+\title{Get Project drive path}
\usage{
CIDA_drive_path(file = "")
}
\arguments{
-\item{file}{(optional) Path to subdirectory/file within CIDA drive}
+\item{file}{(optional) Path to subdirectory/file within the main project(CIDA) drive}
}
\value{
-Full (absolute) file path of CIDA drive
+Full (absolute) file path of project(CIDA) drive plus the subdirectory/file provided.
}
\description{
-This function attempts to get the proper path for the CIDA drive either on
-Windows or Mac.
+This function attempts to get the proper path for the Project(CIDA) drive either on
+Windows or Mac automatically. It returns the full CIDA drive(remote) path
+with the relative path (if provided) appended to the drive path.
+}
+\details{
+If open_project() has been called with a remote path specified the remote path
+will be used first.
+
+If that is not set it will try to determine the drive path. If the expected
+path is not found it will try to load the project metadata path and if that
+fails it looks for a global default path in the user cida_defaults.dcf file.
}
\examples{
# Read data from P1234PIname project
\dontrun{
-df <- read.csv(CIDA_drive_path("BRANCHES/Pulmonary/P1234PIname/DataRaw/data.csv"))
+df <- read.csv(get_project_drive_path("BRANCHES/Pulmonary/P1234PIname/DataRaw/data.csv"))
}
}
diff --git a/man/ProjectAnalyst.Rd b/man/ProjectAnalyst.Rd
index 882ad9a..babf32f 100644
--- a/man/ProjectAnalyst.Rd
+++ b/man/ProjectAnalyst.Rd
@@ -1,5 +1,5 @@
% Generated by roxygen2: do not edit by hand
-% Please edit documentation in R/project_meta_data.R
+% Please edit documentation in R/temp_refactored_message.R
\name{ProjectAnalyst}
\alias{ProjectAnalyst}
\title{Get Project Analyst}
@@ -14,6 +14,3 @@ This function returns the Project Analyst Name. If none exists, it
will return the value of CIDAtools.analyst option or blank if the option
is not set.
}
-\keyword{Analyst}
-\keyword{ProjData}
-\keyword{options}
diff --git a/man/ProjectLocation.Rd b/man/ProjectLocation.Rd
index 1f91ba6..ed56d11 100644
--- a/man/ProjectLocation.Rd
+++ b/man/ProjectLocation.Rd
@@ -1,13 +1,10 @@
% Generated by roxygen2: do not edit by hand
-% Please edit documentation in R/project_meta_data.R
+% Please edit documentation in R/temp_refactored_message.R
\name{ProjectLocation}
\alias{ProjectLocation}
\title{Get Project data location on CIDA Drive}
\usage{
-ProjectLocation(path = "")
-}
-\arguments{
-\item{path}{(optional) a relative path to a particular place in the project}
+ProjectLocation()
}
\value{
full (absolute) file path including the project location on CIDA drive
diff --git a/man/ProjectName.Rd b/man/ProjectName.Rd
index e8d47cc..3f933a0 100644
--- a/man/ProjectName.Rd
+++ b/man/ProjectName.Rd
@@ -1,5 +1,5 @@
% Generated by roxygen2: do not edit by hand
-% Please edit documentation in R/project_meta_data.R
+% Please edit documentation in R/temp_refactored_message.R
\name{ProjectName}
\alias{ProjectName}
\title{Get Project Name}
@@ -12,6 +12,3 @@ A character string with the project name
\description{
This function returns the Project Name or blank if none exists.
}
-\keyword{ProjData}
-\keyword{ProjectName}
-\keyword{options}
diff --git a/man/ProjectPI.Rd b/man/ProjectPI.Rd
index 7317cf0..df5bff0 100644
--- a/man/ProjectPI.Rd
+++ b/man/ProjectPI.Rd
@@ -1,5 +1,5 @@
% Generated by roxygen2: do not edit by hand
-% Please edit documentation in R/project_meta_data.R
+% Please edit documentation in R/temp_refactored_message.R
\name{ProjectPI}
\alias{ProjectPI}
\title{Get PI Name}
@@ -12,6 +12,3 @@ A character string with the PI name
\description{
This function returns the PI Name or blank if none exists.
}
-\keyword{PI}
-\keyword{ProjData}
-\keyword{options}
diff --git a/man/Round.Rd b/man/Round.Rd
index 9fbfe7e..2765ad4 100644
--- a/man/Round.Rd
+++ b/man/Round.Rd
@@ -2,7 +2,7 @@
% Please edit documentation in R/misc_fns.R
\name{Round}
\alias{Round}
-\title{Round and don't drop trailing zeros}
+\title{Round and don't drop trailing zeros - To be deprecated}
\usage{
Round(x, n)
}
diff --git a/man/SetProjectAnalyst.Rd b/man/SetProjectAnalyst.Rd
index 883653a..7112187 100644
--- a/man/SetProjectAnalyst.Rd
+++ b/man/SetProjectAnalyst.Rd
@@ -1,13 +1,13 @@
% Generated by roxygen2: do not edit by hand
-% Please edit documentation in R/project_meta_data.R
+% Please edit documentation in R/temp_refactored_message.R
\name{SetProjectAnalyst}
\alias{SetProjectAnalyst}
\title{Set Project Analyst}
\usage{
-SetProjectAnalyst(AnalystName)
+SetProjectAnalyst(analyst_name)
}
\arguments{
-\item{AnalystName}{A string containing the analyst name}
+\item{analyst_name}{A string containing the analyst name}
}
\value{
A message stating the name has been changed.
@@ -16,6 +16,3 @@ A message stating the name has been changed.
This function allows you to set the project analyst.
This will overwrite the current value if exists.
}
-\keyword{Analyst}
-\keyword{ProjData}
-\keyword{options}
diff --git a/man/SetProjectData.Rd b/man/SetProjectData.Rd
index 20b86e0..c6842d1 100644
--- a/man/SetProjectData.Rd
+++ b/man/SetProjectData.Rd
@@ -1,15 +1,15 @@
% Generated by roxygen2: do not edit by hand
-% Please edit documentation in R/project_meta_data.R
+% Please edit documentation in R/temp_refactored_message.R
\name{SetProjectData}
\alias{SetProjectData}
\title{Set data for project}
\usage{
-SetProjectData(Parameter, Value)
+SetProjectData(parameter, value)
}
\arguments{
-\item{Parameter}{Project Parameter to be set}
+\item{parameter}{Project Parameter to be set}
-\item{Value}{Value to set to project parameter}
+\item{value}{Value to set to project parameter}
}
\description{
Allows you to set misc project data parameters
diff --git a/man/SetProjectLocation.Rd b/man/SetProjectLocation.Rd
index 15f710c..5bebea3 100644
--- a/man/SetProjectLocation.Rd
+++ b/man/SetProjectLocation.Rd
@@ -1,5 +1,5 @@
% Generated by roxygen2: do not edit by hand
-% Please edit documentation in R/project_meta_data.R
+% Please edit documentation in R/temp_refactored_message.R
\name{SetProjectLocation}
\alias{SetProjectLocation}
\title{Set Project Location}
@@ -16,6 +16,3 @@ A message stating the name has been changed.
This function allows you to set the Project's location on the CIDA drive.
This will overwrite the current value if exists.
}
-\keyword{ProjData}
-\keyword{location}
-\keyword{options}
diff --git a/man/SetProjectName.Rd b/man/SetProjectName.Rd
index f123856..720bb87 100644
--- a/man/SetProjectName.Rd
+++ b/man/SetProjectName.Rd
@@ -1,13 +1,13 @@
% Generated by roxygen2: do not edit by hand
-% Please edit documentation in R/project_meta_data.R
+% Please edit documentation in R/temp_refactored_message.R
\name{SetProjectName}
\alias{SetProjectName}
\title{Set Project Name}
\usage{
-SetProjectName(ProjectName)
+SetProjectName(project_name)
}
\arguments{
-\item{ProjectName}{A string containing the analyst name}
+\item{project_name}{A string containing the analyst name}
}
\value{
A message stating the name has been changed.
@@ -16,6 +16,3 @@ A message stating the name has been changed.
This function allows you to set the project name. This will overwrite the
current value if exists.
}
-\keyword{ProjData}
-\keyword{ProjectName}
-\keyword{options}
diff --git a/man/SetProjectPI.Rd b/man/SetProjectPI.Rd
index 44a1bd1..e6f79a9 100644
--- a/man/SetProjectPI.Rd
+++ b/man/SetProjectPI.Rd
@@ -1,13 +1,13 @@
% Generated by roxygen2: do not edit by hand
-% Please edit documentation in R/project_meta_data.R
+% Please edit documentation in R/temp_refactored_message.R
\name{SetProjectPI}
\alias{SetProjectPI}
\title{Set PI Name}
\usage{
-SetProjectPI(PI)
+SetProjectPI(pi)
}
\arguments{
-\item{PI}{A string containing the analyst name}
+\item{pi}{A string containing the analyst name}
}
\value{
A message stating the name has been changed.
@@ -16,6 +16,3 @@ A message stating the name has been changed.
This function allows you to set the Project's PI. This will overwrite the
current value if exists.
}
-\keyword{PI}
-\keyword{ProjData}
-\keyword{options}
diff --git a/man/backup_project.Rd b/man/backup_project.Rd
index c86452e..a8ec040 100644
--- a/man/backup_project.Rd
+++ b/man/backup_project.Rd
@@ -1,8 +1,8 @@
% Generated by roxygen2: do not edit by hand
-% Please edit documentation in R/backup_project.R
+% Please edit documentation in R/project.R
\name{backup_project}
\alias{backup_project}
-\title{Backup Project Directory}
+\title{pull project files from remote directory}
\usage{
backup_project(
path_from = getwd(),
@@ -35,6 +35,9 @@ This function has verbose output to ensure the back up is working, and
ultimately returns a success indicator that's returned by file.copy.
}
\description{
+Backup Project Directory
+}
+\details{
This function backs up a CIDA project to the shared (P) CIDA drive. The backup directory
can either be existing (in which only changed files/folders are updated), or
nonexisting, in which case a full project backup is created.
diff --git a/man/cida_table1.Rd b/man/cida_table1.Rd
index 8ded192..dd9eb02 100644
--- a/man/cida_table1.Rd
+++ b/man/cida_table1.Rd
@@ -2,7 +2,7 @@
% Please edit documentation in R/cida_table1.R
\name{cida_table1}
\alias{cida_table1}
-\title{Create a table one}
+\title{Create a table one - To be deprecated}
\usage{
cida_table1(
data,
diff --git a/man/convertIntervalNotation.Rd b/man/convertIntervalNotation.Rd
index c5f26ae..013dfed 100644
--- a/man/convertIntervalNotation.Rd
+++ b/man/convertIntervalNotation.Rd
@@ -2,7 +2,7 @@
% Please edit documentation in R/misc_fns.R
\name{convertIntervalNotation}
\alias{convertIntervalNotation}
-\title{Convert Interval Notation}
+\title{Convert Interval Notation - To be deprecated}
\usage{
convertIntervalNotation(x)
}
diff --git a/man/create_project.Rd b/man/create_project.Rd
index ef5e821..b8e39a5 100644
--- a/man/create_project.Rd
+++ b/man/create_project.Rd
@@ -1,5 +1,5 @@
% Generated by roxygen2: do not edit by hand
-% Please edit documentation in R/create_project.R
+% Please edit documentation in R/project.R
\name{create_project}
\alias{create_project}
\title{Create Project Directory + readme files}
@@ -8,11 +8,11 @@ create_project(
path = getwd(),
template = c("Admin", "Background", "Code", "DataRaw", "DataProcessed",
"Dissemination", "Reports"),
- ProjectName = "",
- PI = "",
- analyst = "",
- datalocation = "",
- gitlocation = ""
+ project_name,
+ pi = "",
+ analyst,
+ data_location = "",
+ git_location = ""
)
}
\arguments{
@@ -20,15 +20,15 @@ create_project(
\item{template}{Which subdirectories to create}
-\item{ProjectName}{Name of project, or "" for blank}
+\item{project_name}{Name of project, (required)}
-\item{PI}{Name of PI and credentials, or "" for blank}
+\item{pi}{Name of PI and credentials, or "" for blank}
-\item{analyst}{Name of Analyst(s), or "" for blank}
+\item{analyst}{Name of Analyst(s), (required)}
-\item{datalocation}{Location of project on CIDA Drive, or "" for blank}
+\item{data_location}{Location of project on CIDA Drive, or "" for blank}
-\item{gitlocation}{Location project on GitHub}
+\item{git_location}{Location project on GitHub}
}
\value{
This function creates the desired project subdirectories and readmes,
diff --git a/man/find_nearest.Rd b/man/find_nearest.Rd
index dee74b6..12826ff 100644
--- a/man/find_nearest.Rd
+++ b/man/find_nearest.Rd
@@ -3,7 +3,7 @@
\name{find_nearest}
\alias{find_nearest}
\alias{getlower}
-\title{Find the nearest observation to another observation}
+\title{Find the nearest observation to another observation - To be deprecated}
\usage{
find_nearest(
x,
diff --git a/man/getProjectData.Rd b/man/getProjectData.Rd
index 4d0163f..03a7535 100644
--- a/man/getProjectData.Rd
+++ b/man/getProjectData.Rd
@@ -1,5 +1,5 @@
% Generated by roxygen2: do not edit by hand
-% Please edit documentation in R/project_meta_data.R
+% Please edit documentation in R/temp_refactored_message.R
\name{getProjectData}
\alias{getProjectData}
\title{Get data for project}
@@ -7,8 +7,24 @@
getProjectData(param)
}
\arguments{
-\item{param}{Project parameter to be gotten}
+\item{param}{Project parameter to return or if not specified to return all parameter/value pairs.}
}
\description{
-Allows you to get misc project data parameters
+Allows you to get any project data parameters or all parameters. Either specify
+the desired parameter or with no parameter it will return all available parameters.
+}
+\details{
+Possible parameters values include:
+
+ - analyst - Analyst's Name
+
+ - ProjectName - Project Name
+
+ - PI - PI Name
+
+ - datalocation - Poject folder location under the CIDA PATH.
+
+ - default_full_path_to_project - Project default path which is the default full path to the project files. Includes the local filesystem path to network mount point and network path to project folder.
+
+ - gitlocation - GitHub URL for the project code
}
diff --git a/man/get_default_value.Rd b/man/get_default_value.Rd
new file mode 100644
index 0000000..5121b26
--- /dev/null
+++ b/man/get_default_value.Rd
@@ -0,0 +1,19 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/default.R
+\name{get_default_value}
+\alias{get_default_value}
+\title{Get a specific user level default}
+\usage{
+get_default_value(parameter)
+}
+\arguments{
+\item{parameter}{The name of the specific parameter to lookup.}
+}
+\value{
+The user level defaults named parameter
+}
+\description{
+This function returns a specific user level defaults set in ~/cida_defaults.dcf
+}
+\keyword{options}
+\keyword{path}
diff --git a/man/get_defaults.Rd b/man/get_defaults.Rd
new file mode 100644
index 0000000..f70580c
--- /dev/null
+++ b/man/get_defaults.Rd
@@ -0,0 +1,16 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/default.R
+\name{get_defaults}
+\alias{get_defaults}
+\title{Get a list of all user level defaults}
+\usage{
+get_defaults()
+}
+\value{
+The user level defaults
+}
+\description{
+This function returns the user level defaults set in ~/cida_defaults.dcf
+}
+\keyword{options}
+\keyword{path}
diff --git a/man/get_full_project_path.Rd b/man/get_full_project_path.Rd
new file mode 100644
index 0000000..53d72a7
--- /dev/null
+++ b/man/get_full_project_path.Rd
@@ -0,0 +1,14 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/project_meta_data.R
+\name{get_full_project_path}
+\alias{get_full_project_path}
+\title{Gets the currently set full path to the project from .ProjData/Data.dcf}
+\usage{
+get_full_project_path()
+}
+\value{
+full path to project
+}
+\description{
+Gets the currently set full path to the project from .ProjData/Data.dcf
+}
diff --git a/man/get_global_default_analyst.Rd b/man/get_global_default_analyst.Rd
new file mode 100644
index 0000000..6ac9655
--- /dev/null
+++ b/man/get_global_default_analyst.Rd
@@ -0,0 +1,16 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/default.R
+\name{get_global_default_analyst}
+\alias{get_global_default_analyst}
+\title{Get Default Analyst Value}
+\usage{
+get_global_default_analyst()
+}
+\value{
+The default analyst or an empty string if not set.
+}
+\description{
+This function allows you to get the default analyst.
+}
+\keyword{Analyst}
+\keyword{options}
diff --git a/man/get_global_default_path.Rd b/man/get_global_default_path.Rd
new file mode 100644
index 0000000..c81cf7c
--- /dev/null
+++ b/man/get_global_default_path.Rd
@@ -0,0 +1,16 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/default.R
+\name{get_global_default_path}
+\alias{get_global_default_path}
+\title{Get Default drive path}
+\usage{
+get_global_default_path()
+}
+\value{
+The default path
+}
+\description{
+This function returns the user level default drive path set in ~/cida_defaults.dcf
+}
+\keyword{options}
+\keyword{path}
diff --git a/man/get_project_analyst.Rd b/man/get_project_analyst.Rd
new file mode 100644
index 0000000..d995998
--- /dev/null
+++ b/man/get_project_analyst.Rd
@@ -0,0 +1,19 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/project_meta_data.R
+\name{get_project_analyst}
+\alias{get_project_analyst}
+\title{Get Project Analyst}
+\usage{
+get_project_analyst()
+}
+\value{
+A character string with the analyst name
+}
+\description{
+This function returns the Project Analyst Name. If none exists, it
+will return the value of CIDAtools.analyst option or blank if the option
+is not set.
+}
+\keyword{Analyst}
+\keyword{ProjData}
+\keyword{options}
diff --git a/man/get_project_drive_path.Rd b/man/get_project_drive_path.Rd
new file mode 100644
index 0000000..e67c484
--- /dev/null
+++ b/man/get_project_drive_path.Rd
@@ -0,0 +1,34 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/project.R
+\name{get_project_drive_path}
+\alias{get_project_drive_path}
+\title{Get Project drive path}
+\usage{
+get_project_drive_path(file = "")
+}
+\arguments{
+\item{file}{(optional) Path to subdirectory/file within the main project(CIDA) drive}
+}
+\value{
+Full (absolute) file path of project(CIDA) drive plus the subdirectory/file provided.
+}
+\description{
+This function attempts to get the proper path for the Project(CIDA) drive either on
+Windows or Mac automatically. It returns the full CIDA drive(remote) path
+with the relative path (if provided) appended to the drive path.
+}
+\details{
+If open_project() has been called with a remote path specified the remote path
+will be used first.
+
+If that is not set it will try to determine the drive path. If the expected
+path is not found it will try to load the project metadata path and if that
+fails it looks for a global default path in the user cida_defaults.dcf file.
+}
+\examples{
+# Read data from P1234PIname project
+\dontrun{
+df <- read.csv(get_project_drive_path("BRANCHES/Pulmonary/P1234PIname/DataRaw/data.csv"))
+}
+
+}
diff --git a/man/get_project_github.Rd b/man/get_project_github.Rd
new file mode 100644
index 0000000..62147b4
--- /dev/null
+++ b/man/get_project_github.Rd
@@ -0,0 +1,17 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/project_meta_data.R
+\name{get_project_github}
+\alias{get_project_github}
+\title{Get Project GitHub Location}
+\usage{
+get_project_github()
+}
+\value{
+A character string with the project GitHub
+}
+\description{
+This function returns the Project GitHub location or blank if it's not set.
+}
+\keyword{ProjData}
+\keyword{ProjectGitHub}
+\keyword{options}
diff --git a/man/get_project_location.Rd b/man/get_project_location.Rd
new file mode 100644
index 0000000..645b6e7
--- /dev/null
+++ b/man/get_project_location.Rd
@@ -0,0 +1,24 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/project_meta_data.R
+\name{get_project_location}
+\alias{get_project_location}
+\title{Get Project data location on CIDA Drive}
+\usage{
+get_project_location(path = "")
+}
+\arguments{
+\item{path}{(optional) a relative path to a particular place in the project}
+}
+\value{
+full (absolute) file path including the project location on CIDA drive
+}
+\description{
+Get Project data location on CIDA Drive
+}
+\examples{
+# Read data from current project
+\dontrun{
+df <- read.csv(ProjectLocation("DataRaw/my_proj_data.csv"))
+}
+
+}
diff --git a/man/get_project_meta_data.Rd b/man/get_project_meta_data.Rd
new file mode 100644
index 0000000..f31da4a
--- /dev/null
+++ b/man/get_project_meta_data.Rd
@@ -0,0 +1,30 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/project_meta_data.R
+\name{get_project_meta_data}
+\alias{get_project_meta_data}
+\title{Get data for project}
+\usage{
+get_project_meta_data(param = "")
+}
+\arguments{
+\item{param}{Project parameter to return or if not specified to return all parameter/value pairs.}
+}
+\description{
+Allows you to get any project data parameters or all parameters. Either specify
+the desired parameter or with no parameter it will return all available parameters.
+}
+\details{
+Possible parameters values include:
+
+ - analyst - Analyst's Name
+
+ - ProjectName - Project Name
+
+ - PI - PI Name
+
+ - datalocation - Poject folder location under the CIDA PATH.
+
+ - default_full_path_to_project - Project default path which is the default full path to the project files. Includes the local filesystem path to network mount point and network path to project folder.
+
+ - gitlocation - GitHub URL for the project code
+}
diff --git a/man/get_project_name.Rd b/man/get_project_name.Rd
new file mode 100644
index 0000000..b333c4f
--- /dev/null
+++ b/man/get_project_name.Rd
@@ -0,0 +1,17 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/project_meta_data.R
+\name{get_project_name}
+\alias{get_project_name}
+\title{Get Project Name}
+\usage{
+get_project_name()
+}
+\value{
+A character string with the project name
+}
+\description{
+This function returns the Project Name or blank if none exists.
+}
+\keyword{ProjData}
+\keyword{ProjectName}
+\keyword{options}
diff --git a/man/get_project_pi.Rd b/man/get_project_pi.Rd
new file mode 100644
index 0000000..6ab6300
--- /dev/null
+++ b/man/get_project_pi.Rd
@@ -0,0 +1,17 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/project_meta_data.R
+\name{get_project_pi}
+\alias{get_project_pi}
+\title{Get PI Name}
+\usage{
+get_project_pi()
+}
+\value{
+A character string with the PI name
+}
+\description{
+This function returns the PI Name or blank if none exists.
+}
+\keyword{PI}
+\keyword{ProjData}
+\keyword{options}
diff --git a/man/list_kables.Rd b/man/list_kables.Rd
index d796e2a..fe84d02 100644
--- a/man/list_kables.Rd
+++ b/man/list_kables.Rd
@@ -2,7 +2,7 @@
% Please edit documentation in R/reporting_fns.R
\name{list_kables}
\alias{list_kables}
-\title{List tables with the same columns}
+\title{List tables with the same columns - To be deprecated}
\usage{
list_kables(tabs, bo = c("striped", "condensed"), ...)
}
diff --git a/man/nLevelsP.Rd b/man/nLevelsP.Rd
index 8296816..bac292e 100644
--- a/man/nLevelsP.Rd
+++ b/man/nLevelsP.Rd
@@ -2,7 +2,7 @@
% Please edit documentation in R/misc_fns.R
\name{nLevelsP}
\alias{nLevelsP}
-\title{Get pretty number of levels}
+\title{Get pretty number of levels - To be deprecated}
\usage{
nLevelsP(x)
}
diff --git a/man/nrowP.Rd b/man/nrowP.Rd
index 08f9f02..6becb84 100644
--- a/man/nrowP.Rd
+++ b/man/nrowP.Rd
@@ -2,7 +2,7 @@
% Please edit documentation in R/misc_fns.R
\name{nrowP}
\alias{nrowP}
-\title{Get pretty numbers of rows}
+\title{Get pretty numbers of rows - To be deprecated}
\usage{
nrowP(x)
}
diff --git a/man/open_project.Rd b/man/open_project.Rd
new file mode 100644
index 0000000..140ba9a
--- /dev/null
+++ b/man/open_project.Rd
@@ -0,0 +1,24 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/project.R
+\name{open_project}
+\alias{open_project}
+\title{Open Project
+This function sets up the project to work on so the paths can easily be determined.
+When both paths are specified path functions will reference the local copy.
+When one is specified path functions will reference the local or remote copy whichever was specified.
+Future updates will add some functionality to automate tasks.}
+\usage{
+open_project(local_project_folder = "", remote_project_folder = "")
+}
+\arguments{
+\item{local_project_folder}{This is a local copy of the project folder}
+
+\item{remote_project_folder}{This is the location of the shared drive copy of the project folder}
+}
+\description{
+Open Project
+This function sets up the project to work on so the paths can easily be determined.
+When both paths are specified path functions will reference the local copy.
+When one is specified path functions will reference the local or remote copy whichever was specified.
+Future updates will add some functionality to automate tasks.
+}
diff --git a/man/pvalr.Rd b/man/pvalr.Rd
index 0666344..b9dd867 100644
--- a/man/pvalr.Rd
+++ b/man/pvalr.Rd
@@ -2,7 +2,7 @@
% Please edit documentation in R/reporting_fns.R
\name{pvalr}
\alias{pvalr}
-\title{Pretty p-values}
+\title{Pretty p-values - To be deprecated}
\usage{
pvalr(pvals, sig.limit = 0.001, digits = 3, html = FALSE, equal_sign = "")
}
diff --git a/man/pvalue.Rd b/man/pvalue.Rd
index 26f8a24..3b3567c 100644
--- a/man/pvalue.Rd
+++ b/man/pvalue.Rd
@@ -2,7 +2,7 @@
% Please edit documentation in R/cida_table1.R
\name{pvalue}
\alias{pvalue}
-\title{Internal function for p-value calculation in cida_table1}
+\title{Internal function for p-value calculation in cida_table1 - To be deprecated}
\usage{
pvalue(
x,
@@ -27,5 +27,5 @@ across grouped variables.}
use non-parametric hypothesis testing}
}
\description{
-Internal function for p-value calculation in cida_table1
+Internal function for p-value calculation in cida_table1 - To be deprecated
}
diff --git a/man/randblinder_shiny_tool.Rd b/man/randblinder_shiny_tool.Rd
index 4bd408f..02b6185 100644
--- a/man/randblinder_shiny_tool.Rd
+++ b/man/randblinder_shiny_tool.Rd
@@ -2,7 +2,7 @@
% Please edit documentation in R/randomizer_and_blinder_app.R
\name{randblinder_shiny_tool}
\alias{randblinder_shiny_tool}
-\title{Randomizer and blinder tool}
+\title{Randomizer and blinder tool - To be deprecated}
\usage{
randblinder_shiny_tool()
}
diff --git a/man/read_xlsx_color.Rd b/man/read_xlsx_color.Rd
index 7488d40..b5da1c3 100644
--- a/man/read_xlsx_color.Rd
+++ b/man/read_xlsx_color.Rd
@@ -2,7 +2,7 @@
% Please edit documentation in R/read_xlsx_color.R
\name{read_xlsx_color}
\alias{read_xlsx_color}
-\title{Read in xlsx with fill colour}
+\title{Read in xlsx with fill colour - To be deprecated}
\usage{
read_xlsx_color(file, colorColumns, sheet = NULL, header = T)
}
diff --git a/man/removeAnalyst.Rd b/man/removeAnalyst.Rd
index 8f4a0b4..d9c34e8 100644
--- a/man/removeAnalyst.Rd
+++ b/man/removeAnalyst.Rd
@@ -1,21 +1,15 @@
% Generated by roxygen2: do not edit by hand
-% Please edit documentation in R/misc_fns.R
+% Please edit documentation in R/temp_refactored_message.R
\name{removeAnalyst}
\alias{removeAnalyst}
-\title{Remove Default Analyst from ~/.Rprofile}
+\title{Remove Default Analyst from ~/cida_defaults.dcf}
\usage{
-removeAnalyst(quiet = F)
-}
-\arguments{
-\item{quiet}{should a message indicating result be returned, if TRUE will only
-return TRUE or FALSE}
+removeAnalyst()
}
\value{
-Message indicating sucess or failue
+Message indicating success or failure
}
\description{
-This function removes the default analyst set with setAnalyst() from the users
-.Rprofile. If this is the only entry in .Rprofile it will remove the file as well.
+This function removes the default analyst set with set_global_default_analyst()
+ from the users ~/cida_defaults.dcf.
}
-\keyword{Analyst}
-\keyword{remove}
diff --git a/man/remove_global_default_analyst.Rd b/man/remove_global_default_analyst.Rd
new file mode 100644
index 0000000..9ece61b
--- /dev/null
+++ b/man/remove_global_default_analyst.Rd
@@ -0,0 +1,17 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/default.R
+\name{remove_global_default_analyst}
+\alias{remove_global_default_analyst}
+\title{Remove Default Analyst from ~/cida_defaults.dcf}
+\usage{
+remove_global_default_analyst()
+}
+\value{
+Message indicating success or failure
+}
+\description{
+This function removes the default analyst set with set_global_default_analyst()
+ from the users ~/cida_defaults.dcf.
+}
+\keyword{Analyst}
+\keyword{remove}
diff --git a/man/remove_global_default_path.Rd b/man/remove_global_default_path.Rd
new file mode 100644
index 0000000..27afa31
--- /dev/null
+++ b/man/remove_global_default_path.Rd
@@ -0,0 +1,12 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/default.R
+\name{remove_global_default_path}
+\alias{remove_global_default_path}
+\title{removes the default drive path in ~/cida_defaults.dcf}
+\usage{
+remove_global_default_path()
+}
+\description{
+This function removed the default path at the user level to access the project
+drive.
+}
diff --git a/man/setAnalyst.Rd b/man/setAnalyst.Rd
index 2257e4b..0f77a29 100644
--- a/man/setAnalyst.Rd
+++ b/man/setAnalyst.Rd
@@ -1,21 +1,18 @@
% Generated by roxygen2: do not edit by hand
-% Please edit documentation in R/misc_fns.R
+% Please edit documentation in R/temp_refactored_message.R
\name{setAnalyst}
\alias{setAnalyst}
-\title{Set Default Analyst Value}
+\title{Set Project Analyst}
\usage{
-setAnalyst(AnalystName)
+setAnalyst(analyst_name)
}
\arguments{
-\item{AnalystName}{A string containing the analyst name}
+\item{analyst_name}{A string containing the analyst name}
}
\value{
A message stating the name has been changed.
}
\description{
-This function allows you to set the option CIDAtools.analyst permanently
-(until you change it or reinstall CIDAtools) and will
-simultanesouly change the default in New Cida Project Template.
+This function allows you to set the project analyst.
+This will overwrite the current value if exists.
}
-\keyword{Analyst}
-\keyword{options}
diff --git a/man/setPermanentAnalyst.Rd b/man/setPermanentAnalyst.Rd
index 6d8c4d2..82e8dc0 100644
--- a/man/setPermanentAnalyst.Rd
+++ b/man/setPermanentAnalyst.Rd
@@ -1,15 +1,20 @@
% Generated by roxygen2: do not edit by hand
-% Please edit documentation in R/misc_fns.R
+% Please edit documentation in R/temp_refactored_message.R
\name{setPermanentAnalyst}
\alias{setPermanentAnalyst}
-\title{Set Default Analyst Value}
+\title{Set Global Default Analyst Value}
\usage{
-setPermanentAnalyst(Name)
+setPermanentAnalyst(analyst_name, update_template = FALSE)
}
\arguments{
-\item{Name}{A string containing the analyst name}
+\item{analyst_name}{A string containing the analyst name}
+
+\item{update_template}{Bool whether or not to update analyst in the project template.}
+}
+\value{
+A message stating the name has been changed.
}
\description{
-This is an internal function that writes the Default Analyst name to the
-users Rprofile.
+This function allows you to set the default analyst at the user level and
+if possible changes the default analyst in the template for new projects.
}
diff --git a/man/set_default_value.Rd b/man/set_default_value.Rd
new file mode 100644
index 0000000..57ab7d9
--- /dev/null
+++ b/man/set_default_value.Rd
@@ -0,0 +1,16 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/default.R
+\name{set_default_value}
+\alias{set_default_value}
+\title{Sets a default parameter in ~/cida_defaults.dcf}
+\usage{
+set_default_value(parameter, value)
+}
+\arguments{
+\item{parameter}{parameter name}
+
+\item{value}{new value}
+}
+\description{
+This function sets a default parameter at the user level.
+}
diff --git a/man/set_full_project_path.Rd b/man/set_full_project_path.Rd
new file mode 100644
index 0000000..62883c3
--- /dev/null
+++ b/man/set_full_project_path.Rd
@@ -0,0 +1,17 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/project_meta_data.R
+\name{set_full_project_path}
+\alias{set_full_project_path}
+\title{Sets the default full path to the project.}
+\usage{
+set_full_project_path(path = "")
+}
+\arguments{
+\item{path}{full path to the project folder}
+}
+\value{
+message indicating the path has been saved.
+}
+\description{
+Sets the default full path to the project.
+}
diff --git a/man/set_global_default_analyst.Rd b/man/set_global_default_analyst.Rd
new file mode 100644
index 0000000..e437e58
--- /dev/null
+++ b/man/set_global_default_analyst.Rd
@@ -0,0 +1,22 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/default.R
+\name{set_global_default_analyst}
+\alias{set_global_default_analyst}
+\title{Set Global Default Analyst Value}
+\usage{
+set_global_default_analyst(analyst_name, update_template = FALSE)
+}
+\arguments{
+\item{analyst_name}{A string containing the analyst name}
+
+\item{update_template}{Bool whether or not to update analyst in the project template.}
+}
+\value{
+A message stating the name has been changed.
+}
+\description{
+This function allows you to set the default analyst at the user level and
+if possible changes the default analyst in the template for new projects.
+}
+\keyword{Analyst}
+\keyword{options}
diff --git a/man/set_global_default_path.Rd b/man/set_global_default_path.Rd
new file mode 100644
index 0000000..f32ecf8
--- /dev/null
+++ b/man/set_global_default_path.Rd
@@ -0,0 +1,19 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/default.R
+\name{set_global_default_path}
+\alias{set_global_default_path}
+\title{Sets a default drive path in ~/cida_defaults.dcf}
+\usage{
+set_global_default_path(path = "")
+}
+\arguments{
+\item{path}{Path to the main project(CIDA) drive}
+}
+\value{
+Message that path was set.
+}
+\description{
+This function sets a default path at the user level to access the project
+drive. If the drive is not detected automatically this file will be used to
+set a default path if set.
+}
diff --git a/man/set_project_analyst.Rd b/man/set_project_analyst.Rd
new file mode 100644
index 0000000..352217d
--- /dev/null
+++ b/man/set_project_analyst.Rd
@@ -0,0 +1,21 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/project_meta_data.R
+\name{set_project_analyst}
+\alias{set_project_analyst}
+\title{Set Project Analyst}
+\usage{
+set_project_analyst(analyst_name)
+}
+\arguments{
+\item{analyst_name}{A string containing the analyst name}
+}
+\value{
+A message stating the name has been changed.
+}
+\description{
+This function allows you to set the project analyst.
+This will overwrite the current value if exists.
+}
+\keyword{Analyst}
+\keyword{ProjData}
+\keyword{options}
diff --git a/man/set_project_github.Rd b/man/set_project_github.Rd
new file mode 100644
index 0000000..913e57d
--- /dev/null
+++ b/man/set_project_github.Rd
@@ -0,0 +1,21 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/project_meta_data.R
+\name{set_project_github}
+\alias{set_project_github}
+\title{Set Project GitHub Location}
+\usage{
+set_project_github(git_url = "")
+}
+\arguments{
+\item{git_url}{A string containing the URL to the GitHub repository for this project.}
+}
+\value{
+A message stating the name has been changed.
+}
+\description{
+This function allows you to set the Project's GitHub location.
+This will overwrite the current value if exists.
+}
+\keyword{ProjData}
+\keyword{location}
+\keyword{options}
diff --git a/man/set_project_location.Rd b/man/set_project_location.Rd
new file mode 100644
index 0000000..37e85dd
--- /dev/null
+++ b/man/set_project_location.Rd
@@ -0,0 +1,21 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/project_meta_data.R
+\name{set_project_location}
+\alias{set_project_location}
+\title{Set Project Location}
+\usage{
+set_project_location(path)
+}
+\arguments{
+\item{path}{A string containing the file path to the project location on CIDA drive}
+}
+\value{
+A message stating the name has been changed.
+}
+\description{
+This function allows you to set the Project's location on the CIDA drive.
+This will overwrite the current value if exists.
+}
+\keyword{ProjData}
+\keyword{location}
+\keyword{options}
diff --git a/man/set_project_meta_data.Rd b/man/set_project_meta_data.Rd
new file mode 100644
index 0000000..49250a7
--- /dev/null
+++ b/man/set_project_meta_data.Rd
@@ -0,0 +1,17 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/project_meta_data.R
+\name{set_project_meta_data}
+\alias{set_project_meta_data}
+\title{Set data for project}
+\usage{
+set_project_meta_data(parameter, value)
+}
+\arguments{
+\item{parameter}{Project Parameter to be set}
+
+\item{value}{Value to set to project parameter}
+}
+\description{
+Allows you to set misc project data parameters
+for Project Name, Analyst, or PI recommend you use specific function
+}
diff --git a/man/set_project_name.Rd b/man/set_project_name.Rd
new file mode 100644
index 0000000..9d68219
--- /dev/null
+++ b/man/set_project_name.Rd
@@ -0,0 +1,21 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/project_meta_data.R
+\name{set_project_name}
+\alias{set_project_name}
+\title{Set Project Name}
+\usage{
+set_project_name(project_name)
+}
+\arguments{
+\item{project_name}{A string containing the analyst name}
+}
+\value{
+A message stating the name has been changed.
+}
+\description{
+This function allows you to set the project name. This will overwrite the
+current value if exists.
+}
+\keyword{ProjData}
+\keyword{ProjectName}
+\keyword{options}
diff --git a/man/set_project_pi.Rd b/man/set_project_pi.Rd
new file mode 100644
index 0000000..31e1e25
--- /dev/null
+++ b/man/set_project_pi.Rd
@@ -0,0 +1,21 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/project_meta_data.R
+\name{set_project_pi}
+\alias{set_project_pi}
+\title{Set PI Name}
+\usage{
+set_project_pi(pi)
+}
+\arguments{
+\item{pi}{A string containing the analyst name}
+}
+\value{
+A message stating the name has been changed.
+}
+\description{
+This function allows you to set the Project's PI. This will overwrite the
+current value if exists.
+}
+\keyword{PI}
+\keyword{ProjData}
+\keyword{options}
diff --git a/man/sum_ignore_NA.Rd b/man/sum_ignore_NA.Rd
index 90b2692..c037d37 100644
--- a/man/sum_ignore_NA.Rd
+++ b/man/sum_ignore_NA.Rd
@@ -2,7 +2,7 @@
% Please edit documentation in R/misc_fns.R
\name{sum_ignore_NA}
\alias{sum_ignore_NA}
-\title{Sum ignoring NAs}
+\title{Sum ignoring NAs - To be deprecated}
\usage{
sum_ignore_NA(...)
}
diff --git a/man/tidy.power.htest.Rd b/man/tidy.power.htest.Rd
new file mode 100644
index 0000000..a0d43c9
--- /dev/null
+++ b/man/tidy.power.htest.Rd
@@ -0,0 +1,16 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/misc_fns.R
+\name{tidy.power.htest}
+\alias{tidy.power.htest}
+\title{Helper for pwr package version of power fns. - To be deprecated}
+\usage{
+\method{tidy}{power.htest}(x, ...)
+}
+\arguments{
+\item{x}{description}
+
+\item{...}{description}
+}
+\description{
+Helper for pwr package version of power fns. - To be deprecated
+}
diff --git a/man/vec_power.Rd b/man/vec_power.Rd
index 6f9ddea..60917e8 100644
--- a/man/vec_power.Rd
+++ b/man/vec_power.Rd
@@ -2,7 +2,7 @@
% Please edit documentation in R/misc_fns.R
\name{vec_power}
\alias{vec_power}
-\title{Vectorized power estimates}
+\title{Vectorized power estimates - To be deprecated}
\usage{
vec_power(fun = stats::power.t.test, ...)
}
diff --git a/tests/testthat.R b/tests/testthat.R
new file mode 100644
index 0000000..3bfc391
--- /dev/null
+++ b/tests/testthat.R
@@ -0,0 +1,12 @@
+# This file is part of the standard setup for testthat.
+# It is recommended that you do not modify it.
+#
+# Where should you do additional test configuration?
+# Learn more about the roles of various files in:
+# * https://r-pkgs.org/testing-design.html#sec-tests-files-overview
+# * https://testthat.r-lib.org/articles/special-files.html
+
+library(testthat)
+library(CIDAtools)
+
+test_check("CIDAtools")
diff --git a/tests/testthat/test_default.R b/tests/testthat/test_default.R
new file mode 100644
index 0000000..f06d2f6
--- /dev/null
+++ b/tests/testthat/test_default.R
@@ -0,0 +1,83 @@
+home_dir <- fs::path_home()
+temp_path <-fs::path_join(c(home_dir,"/cida_defaults.dcf"))
+
+
+test_that("create temporary dcf file and test reading it", {
+ dcf_content <- list( path="~/test_drive", analyst_name="Analyst Name")
+ write.dcf(dcf_content, file.path(temp_path))
+
+ # Process the DCF file using your function
+ default_data <- read_global_defaults()
+
+ # Expectations
+ expect_equal(default_data$path, "~/test_drive")
+ expect_equal(default_data$analyst_name, "Analyst Name")
+
+
+ # Clean up the temporary file
+ #unlink(temp_dcf_file)
+})
+
+test_that("test getter functions", {
+
+ default_data <- get_defaults()
+
+ # Expectations
+ expect_equal(default_data$path, "~/test_drive")
+ expect_equal(default_data$analyst_name, "Analyst Name")
+
+})
+
+test_that("test getter functions", {
+
+ analyst_name <- get_default_value("analyst_name")
+ expect_equal(analyst_name, "Analyst Name")
+
+ path <- get_global_default_path()
+ analyst_name <- get_global_default_analyst()
+ # Expectations
+ expect_equal(path, "~/test_drive")
+ expect_equal(analyst_name, "Analyst Name")
+
+
+ expect_warning(non_existent <- get_default_value("name"),"Parameter:name does not exist in default values.")
+ expect_equal(non_existent,'')
+
+})
+
+test_that("test setter functions",{
+ msg1 <- set_global_default_analyst("Analyst Name2")
+ msg2 <- set_global_default_path("~/test_drive2")
+ expect_equal(msg1,"The default analyst name has been changed to Analyst Name2")
+ expect_equal(msg2,"The default project path has been changed to ~/test_drive2")
+
+ path <- get_global_default_path()
+ analyst_name <- get_global_default_analyst()
+ expect_equal(path, "~/test_drive2")
+ expect_equal(analyst_name, "Analyst Name2")
+
+})
+
+test_that("test remove functions",{
+ remove_global_default_path()
+ remove_global_default_analyst()
+ path <- get_global_default_path()
+ expect_warning(analyst_name <- get_global_default_analyst(),"Parameter:analyst_name does not exist in default values.")
+ expect_equal(path, "")
+ expect_equal(analyst_name, "")
+})
+
+
+test_that("test updating the template with set_global_default_analyst",{
+ msg1 <- set_global_default_analyst("Analyst Name3",update_template=FALSE)
+ expect_equal(msg1,"The default analyst name has been changed to Analyst Name3")
+})
+
+unlink(temp_path)
+
+test_that("test getting values after deletion",{
+ w <- capture_warnings(path <- get_global_default_path())
+ expect_match(w, "~/cida_defaults\\.dcf at full path:.*cida_defaults\\.dcf does not exist\\.\\nNothing was loaded\\.",fixed=FALSE, all = FALSE)
+ expect_match(w, "Parameter:path does not exist in default values\\.",fixed=FALSE, all=FALSE)
+ expect_equal(path,'')
+})
diff --git a/tests/testthat/test_misc_fns.R b/tests/testthat/test_misc_fns.R
new file mode 100644
index 0000000..e69de29
diff --git a/tests/testthat/test_project.R b/tests/testthat/test_project.R
new file mode 100644
index 0000000..791450c
--- /dev/null
+++ b/tests/testthat/test_project.R
@@ -0,0 +1,147 @@
+home_dir <- fs::path_home()
+test_drive_dir <- fs::path_expand("~/test_drive")
+fs::dir_create(path=test_drive_dir)
+test_project_path <- "BRANCHES/dr_test/test_project/"
+
+unlink(paste(test_drive_dir,"/",test_project_path,sep=""))
+unlink(paste(test_drive_dir,"/","BRANCHES/dr_test/",sep=""))
+
+full_path <- paste0(test_drive_dir,"/",test_project_path)
+
+
+
+test_that("test project creation",{
+ create_project(path=full_path,
+ project_name="Test Project", pi="Dr. Test",analyst ="Test Name",
+ data_location ="BRANCHES/dr_test/test_project",
+ git_location="CIDA/Test_test_project" )
+ expect_equal(file.exists(paste0(full_path,"/Admin/README.md")), TRUE)
+ expect_equal(file.exists(paste0(full_path,"/Background/README.md")), TRUE)
+ expect_equal(file.exists(paste0(full_path,"/Code/README.md")), TRUE)
+ expect_equal(file.exists(paste0(full_path,"/DataProcessed/README.md")), TRUE)
+ expect_equal(file.exists(paste0(full_path,"/DataRaw/README.md")), TRUE)
+ expect_equal(file.exists(paste0(full_path,"/Dissemination/README.md")), TRUE)
+ expect_equal(file.exists(paste0(full_path,"/README.md")), TRUE)
+ expect_equal(file.exists(paste0(full_path,"/Reports/README.md")), TRUE)
+ expect_equal(dir.exists(paste0(full_path,"/.ProjData")), TRUE)
+ expect_equal(file.exists(paste0(full_path,"/.ProjData/Data.dcf")), TRUE)
+ expect_equal(file.exists(paste0(full_path,"/test_project.Rproj")), TRUE)
+ expect_equal(file.exists(paste0(full_path,"/.Rprofile")), TRUE)
+})
+test_that("create_project errors when project_name is missing", {
+ expect_error(
+ create_project(path = tempdir(), analyst = "Test"),
+ "'project_name' is required and cannot be empty."
+ )
+})
+
+#test_that("create_project errors when analyst is missing", {
+# expect_error(
+# create_project(path = tempdir(), project_name = "Test"),
+# "'analyst' is required and cannot be empty."
+# )
+#})
+
+test_that("create_project errors when project_name is empty string", {
+ expect_error(
+ create_project(path = tempdir(), project_name = "", analyst = "Test"),
+ "'project_name' is required and cannot be empty."
+ )
+})
+
+#test_that("create_project errors when analyst is empty string", {
+# expect_error(
+# create_project(path = tempdir(), project_name = "Test", analyst = ""),
+# "'analyst' is required and cannot be empty."
+# )
+#})
+
+test_that("metadata file is always created", {
+ temp_path <- file.path(tempdir(), "test_meta_always")
+ unlink(temp_path, recursive = TRUE)
+ create_project(path = temp_path,
+ project_name = "Meta Test",
+ analyst = "Test Analyst")
+ expect_true(dir.exists(file.path(temp_path, ".ProjData")))
+ expect_true(file.exists(file.path(temp_path, ".ProjData/Data.dcf")))
+ unlink(temp_path, recursive = TRUE)
+})
+
+test_that("test open_project",{
+ open_project(remote_project_folder=full_path)
+ expect_equal(as.character(options("cida_tools.remote_current_project_path")), full_path)
+})
+
+test_that("test project meta data",{
+ options(cida_tools.remote_current_project_path= "")
+
+ # Process the DCF file using your function
+ w <- capture_warnings(github <- get_project_github())
+ expect_match(w,".ProjData directory not found in project.",all=FALSE)
+ expect_match(w,".ProjData/Data.dcf File does not exist.",all=FALSE)
+ expect_equal(github, "")
+
+ w <- capture_warnings(proj_name <- get_project_name())
+ expect_match(w,".ProjData directory not found in project.",all=FALSE)
+ expect_match(w,".ProjData/Data.dcf File does not exist.",all=FALSE)
+ expect_equal(proj_name, "")
+ w <- capture_warnings(pi <- get_project_pi())
+ expect_match(w,".ProjData directory not found in project.",all=FALSE)
+ expect_match(w,".ProjData/Data.dcf File does not exist.",all=FALSE)
+ expect_equal(pi, "")
+ w <- capture_warnings(analyst <- get_project_analyst())
+ expect_match(w,".ProjData directory not found in project.",all=FALSE)
+ expect_match(w,".ProjData/Data.dcf File does not exist.",all=FALSE)
+ expect_equal(analyst,"")
+ w <- capture_warnings(location <- get_project_location())
+ expect_match(w,".ProjData directory not found in project.",all=FALSE)
+ expect_match(w,".ProjData/Data.dcf File does not exist.",all=FALSE)
+ expect_equal(location,fs::path(""))
+
+ open_project(remote_project_folder=full_path)
+ # Process the DCF file using your function
+ github <- get_project_github()
+ proj_name <- get_project_name()
+ pi <- get_project_pi()
+ analyst <- get_project_analyst()
+ location <- get_project_location()
+ # Expectations
+ expect_equal(github, "CIDA/Test_test_project")
+ expect_equal(proj_name, "Test Project")
+ expect_equal(pi, "Dr. Test")
+ expect_equal(analyst,"Test Name")
+ expect_equal(location,fs::path("BRANCHES/dr_test/test_project/"))
+
+ options(cida_tools.remote_current_project_path= "")
+
+ setwd(full_path)
+ rm(github, proj_name, pi, analyst, location)
+ # Process the DCF file using your function
+ github <- get_project_github()
+ proj_name <- get_project_name()
+ pi <- get_project_pi()
+ analyst <- get_project_analyst()
+ location <- get_project_location()
+ # Expectations
+ expect_equal(github, "CIDA/Test_test_project")
+ expect_equal(proj_name, "Test Project")
+ expect_equal(pi, "Dr. Test")
+ expect_equal(analyst,"Test Name")
+ expect_equal(location,fs::path("BRANCHES/dr_test/test_project/"))
+
+})
+
+test_that("get project drive path",{
+ open_project(remote_project_folder=full_path)
+ drive_path <- get_project_drive_path()
+ expect_equal(drive_path,test_drive_dir)
+
+ options(cida_tools.remote_current_project_path= "")
+ errMsg <- tryCatch({get_project_drive_path()}, error=function(x) {geterrmessage()})
+ expect_match(errMsg, "Nothing found at (.*?) ensure drive is mounted and you have entered your password to access the drive \\(and are logged into the VPN if needed\\.\\) If still experiencing issues try set_project_data_path\\(\\) or set_global_default_path\\(\\)")
+ #expect_equal(errMsg, "Nothing found at /Volumes/dept || SPH || SPH-CIDA || BRANCHES Please ensure drive is mounted and you have entered your password to access the drive (and are logged into the VPN if needed.) If still experiencing issues try set_project_data_path() or set_global_default_path()")
+ # Since the above call to get_project_drive_path() will error out, drive_path retains the old value from the first call. Commenting out for now to prevent the check.
+ #expect_equal(drive_path,"")
+})
+
+unlink(paste(test_drive_dir,"/",test_project_path,sep=""))
diff --git a/tests/testthat/test_project_internal.R b/tests/testthat/test_project_internal.R
new file mode 100644
index 0000000..6cc475d
--- /dev/null
+++ b/tests/testthat/test_project_internal.R
@@ -0,0 +1,39 @@
+home_dir <- fs::path_home()
+
+global_path <-fs::path_join(c(home_dir,"/cida_defaults.dcf"))
+
+test_drive_dir <- fs::path_expand("~/test_drive")
+fs::dir_create(path=test_drive_dir)
+test_project_path <- "BRANCHES/dr_test/test_project5"
+full_project_dir <- paste(test_drive_dir,test_project_path,"/.ProjData/",sep="")
+fs::dir_create(path= full_project_dir)
+
+test_that("test the get_default_path function",{
+ w <- capture_warnings(test_path <- get_default_path())
+ expect_equal(test_path,"")
+ expect_match(w,".ProjData/Data.dcf File does not exist.",all=FALSE)
+ expect_match(w,".ProjData directory not found in project.",all=FALSE)
+
+ #Create Global Default File
+ dcf_content <- list( path="~/test_drive", analyst_name="Analyst Name")
+ write.dcf(dcf_content, file.path(global_path))
+ w <- capture_warnings(test_path <- get_default_path())
+ full_path_test <- as.character(fs::path_abs("~/test_drive"))
+ expect_equal(test_path,full_path_test)
+
+ #Create Project MetaData File
+ setwd(paste(test_drive_dir,test_project_path,sep=""))
+ dcf_content <- list( ProjectName="Test Project 5", PI="Dr. Test",analyst="Analyst Name",datalocation="Branches/dr_test/test_project5",gitlocation="CIDATools/Test_test_project5",default_full_path_to_project="~/test_drive/Branches/dr_test/test_project5")
+ w <- capture_warnings(save_project_data(dcf_content))
+ #expect_match(w,".ProjData/Data.dcf File does not exist.",all=FALSE)
+
+
+ w <- capture_warnings(test_path <- get_default_path())
+ full_path_test <- fs::path_abs("~/test_drive")
+ expect_equal(test_path,full_path_test)
+
+
+})
+
+
+unlink(global_path)
diff --git a/tests/testthat/test_project_meta_data.R b/tests/testthat/test_project_meta_data.R
new file mode 100644
index 0000000..330c0c1
--- /dev/null
+++ b/tests/testthat/test_project_meta_data.R
@@ -0,0 +1,62 @@
+home_dir <- fs::path_home()
+test_drive_dir <- fs::path_expand("~/test_drive/")
+fs::dir_create(path=test_drive_dir)
+test_project_path <- "BRANCHES/dr_test/test_project"
+full_project_dir <- paste(test_drive_dir,test_project_path,"/.ProjData/",sep="")
+fs::dir_create(path= full_project_dir)
+
+unlink(paste(full_project_dir,"Data.dcf",sep=""))
+
+test_that("create a test project dcf file and test getter functions", {
+ setwd(paste(test_drive_dir,test_project_path,sep=""))
+ dcf_content <- list( ProjectName="Test Project 5", PI="Dr. Test",analyst="Analyst Name",datalocation="BRANCHES/dr_test/test_project",gitlocation="CIDATools/Test_test_project")
+
+ w <- capture_warnings(save_project_data(dcf_content))
+ expect_match(w,".ProjData/Data.dcf File does not exist.", perl=TRUE ,all=FALSE)
+ #expect_warning(save_project_data(dcf_content),".ProjData/Data.dcf file not found in project.")
+
+ # Process the DCF file using your function
+ github <- get_project_github()
+ proj_name <- get_project_name()
+ pi <- get_project_pi()
+ analyst <- get_project_analyst()
+ location <- get_project_location()
+ # Expectations
+ expect_equal(github, "CIDATools/Test_test_project")
+ expect_equal(proj_name, "Test Project 5")
+ expect_equal(pi, "Dr. Test")
+ expect_equal(analyst,"Analyst Name")
+ expect_equal(location,fs::path("BRANCHES/dr_test/test_project/"))
+
+ })
+
+ test_that("create a test project dcf file and test setter/getter functions", {
+ set_project_analyst("Analyst 2")
+ set_project_name("Project 1")
+ set_project_pi("Dr. Test2")
+ set_project_location("BRANCHES/dr_test/test_project2/")
+ set_project_github("CIDATools/Test2_test_project2")
+
+ expect_equal(get_project_analyst(),"Analyst 2")
+ expect_equal(get_project_name(),"Project 1")
+ expect_equal(get_project_pi(),"Dr. Test2")
+ expect_equal(get_project_location(),fs::path("BRANCHES/dr_test/test_project2/"))
+ expect_equal(get_project_github(),"CIDATools/Test2_test_project2")
+
+ })
+
+test_that("test setting/getting full project path",{
+ test_full_path <- fs::path_abs(fs::path_join(c(test_drive_dir,test_project_path)))
+
+ w <- capture_warnings(before_set<-get_full_project_path())
+ expect_match(w,"default_full_path_to_project not found in project data.",all=FALSE)
+ expect_equal(before_set,"")
+
+ msg <- set_full_project_path(path=test_full_path)
+ expect_match(msg,paste("The project default full path has been changed to ",test_full_path,sep=""), all=FALSE)
+
+
+
+})
+
+unlink(paste(full_project_dir,"Data.dcf",sep=""))
diff --git a/tests/testthat/test_util_internal.R b/tests/testthat/test_util_internal.R
new file mode 100644
index 0000000..fa55a29
--- /dev/null
+++ b/tests/testthat/test_util_internal.R
@@ -0,0 +1,4 @@
+test_that("test check_string_param_value", {
+ expect_error(val<-check_string_param_value(1,"test") ,"test must be a character string")
+ expect_warning(val<-check_string_param_value(c("string1","string2"),"test") ,"Only First String is Used")
+})
diff --git a/vignettes/.gitignore b/vignettes/.gitignore
deleted file mode 100644
index 097b241..0000000
--- a/vignettes/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-*.html
-*.R
diff --git a/vignettes/CIDA_BIOS_Cluster.Rmd b/vignettes/CIDA_BIOS_Cluster.Rmd
deleted file mode 100644
index a3d1120..0000000
--- a/vignettes/CIDA_BIOS_Cluster.Rmd
+++ /dev/null
@@ -1,262 +0,0 @@
----
-title: "Computing on the CSPH Biostats Cluster"
-author: "Research Tools Committee"
-date: "Last Updated: `r Sys.Date()`"
-output: rmarkdown::html_vignette
-vignette: >
- %\VignetteIndexEntry{Computing on the CSPH Biostats Cluster}
- %\VignetteEngine{knitr::rmarkdown}
- %\VignetteEncoding{UTF-8}
----
-
-```{r setup, include=FALSE}
-knitr::opts_chunk$set(echo = TRUE)
-```
-
-## Definitions
-- **HPC** - High-performance Computing
-- **Node** - A single computer in the cluster's network. Most HPC clusters have a *head node* and one or more *compute nodes*
-- **Head Node** - A node within the cluster which serves as the user's access/login point to the cluster. Depending on cluster configuration, the head node may also be responsible for scheduling and distributing jobs to the compute nodes.
-- **Compute Node** - A node within the cluster which is designated for running user-submitting jobs. Compute nodes usually offer large amounts of computational resources (CPU cores, RAM, etc).
-- **Cluster** - A group of networked computers, usually running cluster-management software to coordinate resource sharing among multiple users.
-- **Job** - A computational task executed on the cluster. A submitted job will be scheduled and executed on one of the compute nodes.
-
-## Introduction to HPC (High-Performance Computing)
-
-An HPC cluster is a group of networked high-performance computers (*nodes*).
-
-A typical cluster will have multiple *compute nodes* which can perform heavy computation, as well as a *head node* which serves as the user's access point to the cluster, and may also be responsible for scheduling jobs among the *compute nodes*.
-The *compute nodes* in an cluster typically have compute resources (CPU Cores, RAM, Disk Space) which far exceed those of a typical laptop or desktop computer.
-
-Because HPC clusters are intended to serve a group of people (i.e. A biostatistics department) rather than a single user, HPC clusters use the concept of [jobs](#def_job) to allow for multiple users to effectively share the cluster's resources.
-
-When a user is ready to run something (an analysis, processing pipeline, etc) on the cluster, they will submit a new *job* to the cluster. The cluster will then schedule and run the job as soon as compute resources are available.
-
-```{r, echo=FALSE, out.width="80%", fig.align="center"}
-knitr::include_graphics("figures/CIDA_BIOS_Cluster/cluster_basic_diagram.png")
-```
-
-The example figure above shows an example cluster with three users. Each user connects to the Head Node to submit their jobs.
-
- User 1 has submitted two jobs, which are both running on Compute Node 1. User 2 has submitted a single job, which is also running on Compute Node 2. User 3 has submitted a job which requires a larger amount of compute resources (CPU cores, RAM, etc). This job runs on Compute Node 2 to provide the user with the resources they requested.
-
-HPC clusters are useful for:
-
-1. Performing analyses which take a long time to run (i.e. A large-scale analysis which takes hours to complete)
-2. Performing analyses which are too resource-intensive (require too much RAM, Disk Space, etc) to run on a typical computer.
-
-## CSPH Biostats HPC Cluster
-
-The CSPH Biostats cluster consists of four nodes. The `csphbiostats.ucdenver.pvt` node serves as both a head node and one of the compute nodes (i.e. Submitted jobs may also run on this node), and the `cidalappc[1-3].ucdenver.pvt` nodes serve as compute nodes.
-
-```{r, echo=FALSE, out.width="100%", fig.align="center"}
-knitr::include_graphics("figures/CIDA_BIOS_Cluster/Biostats_HPC_diagram.png")
-```
-
-The CIDA/Biostats server uses the [SLURM](https://slurm.schedmd.com) system to manage job scheduling and resource management on the cluster.
-
-## Accessing the CSPH Biostats Cluster
-
-To access the CSPH Biostats cluster, first submit a support ticket on the [SOM IS web page](https://medschool.cuanschutz.edu/informationservices) requesting:
-
-1. Access to the 'CSPH/CIDA Biostats Cluster'.
-2. (optional) A directory under `/biostats_share` (i.e. `/biostats_share/Host biostats
- HostName csphbiostats.ucdenver.pvt
- User your_username
- Port 22
- LocalForward 8895 /tmp/jupyter-your_username.sock
- LocalForward 8896 /tmp/rstudio-your-username.sock
-
-