Commit 7f83b771 authored by Ashley Stewart's avatar Ashley Stewart 💃
Browse files

Merge branch 'file_paths' into 'master'

Fixed SDrivePaths( ) to work with more than two versions of the longitudinal dataset

See merge request aspree/aspree-r-package!37
parents bd146310 1ce43c71
...@@ -25,19 +25,12 @@ SDrivePaths <- function(ver = 3, prefix = NA) { ...@@ -25,19 +25,12 @@ SDrivePaths <- function(ver = 3, prefix = NA) {
stop("Please specify the prefix for S Drive data, e.g. \"S:/MNHS-SPHPM-EPM/ASPREE-Data/ASPREE Longitudinal Data Set/\"") stop("Please specify the prefix for S Drive data, e.g. \"S:/MNHS-SPHPM-EPM/ASPREE-Data/ASPREE Longitudinal Data Set/\"")
} }
} }
path_pattern <- file.path(prefix, "ASPREE-Data", "ASPREE Longitudinal Data Set", "LOCKED", "ASPREE Longitudinal Data Set Version*")
prefixF2_DMC <- file.path(prefix, "ASPREE-Data", "ASPREE Longitudinal Data Set", "Drafts", "Version 2") prefix <- Sys.glob(path_pattern)
prefix <- Sys.glob(file.path(prefix, "ASPREE-Data", "ASPREE Longitudinal Data Set", "LOCKED", "ASPREE Longitudinal Data Set Version*"))
prefix <- prefix[file.info(prefix)$isdir] prefix <- prefix[file.info(prefix)$isdir]
common_prefix <- suppressWarnings(
min( common_prefix <- nchar(path_pattern)
which(
Reduce(f = "!=", lapply(prefix, function(x) {
substring(x, seq(1, nchar(x)), seq(1, nchar(x)))
}), accumulate = FALSE)
)
)
)
versions <- substring(prefix, common_prefix) versions <- substring(prefix, common_prefix)
prefix <- substring(prefix[1], 1, common_prefix - 1) prefix <- substring(prefix[1], 1, common_prefix - 1)
ver_possible <- sapply(versions, function(x) {startsWith(x, as.character(ver))}) ver_possible <- sapply(versions, function(x) {startsWith(x, as.character(ver))})
...@@ -71,7 +64,7 @@ SDrivePaths <- function(ver = 3, prefix = NA) { ...@@ -71,7 +64,7 @@ SDrivePaths <- function(ver = 3, prefix = NA) {
SectionG1 = Sys.glob(file.path(prefix, "CSV*", "SectionG1_*.csv")), SectionG1 = Sys.glob(file.path(prefix, "CSV*", "SectionG1_*.csv")),
SectionG2 = Sys.glob(file.path(prefix, "CSV*", "SectionG2_*.csv")), SectionG2 = Sys.glob(file.path(prefix, "CSV*", "SectionG2_*.csv")),
SectionH1 = Sys.glob(file.path(prefix, "CSV*", "SectionH1_*.csv")), SectionH1 = Sys.glob(file.path(prefix, "CSV*", "SectionH1_*.csv")),
SectionF2_DMC = Sys.glob(file.path(prefixF2_DMC, "SectionF2_*.dta")) SectionF2_DMC = Sys.glob(file.path(prefix, "DMC*", "SectionF2_*.dta"))
) )
if (!all(lapply(paths, length) == 1)) { if (!all(lapply(paths, length) == 1)) {
warning("Some sections not found!") warning("Some sections not found!")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment