Skip to content

Commit

Permalink
Merge branch 'individual_inputs'
Browse files Browse the repository at this point in the history
Accept clc and hbpc input files individually.
Remove brittle input directory API.
  • Loading branch information
grosscol committed Jun 27, 2018
2 parents b61adde + f5ae3d6 commit 11e9a24
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 248 deletions.
40 changes: 26 additions & 14 deletions R/main.r
Original file line number Diff line number Diff line change
@@ -1,46 +1,58 @@
#' @title Main
#' @description Build all reports for input data in input directory
#' @note This is the entry point for the application.
#' @param input_dir path to directory that contains clc.csv or hbpc.csv
#' @param ... paths to input files for clc, hbpc, or dementia reports
#' @param config_path path to configuration file
#' @param output_dir path to output directory. Defaults to input_dir
#' @return boolean TRUE indicates successful run.
#' @export
#'
main <- function(input_dir, config_path, output_dir = NULL){
main <- function(config_path, output_dir = NULL, ...){
cat("\nDEBUG\n")
cat(config_path)
cat("\nDEBUG\n")
cat(output_dir)
cat("\n")

input_args <- list(...)

# Ignore warnings
options(warn = -1)

# Default to using same directory for input and output
if(is.null(output_dir)){ output_dir <- input_dir }
# Default to using working directory output
if(is.null(output_dir)){ output_dir <- getwd() }

config <- read_config(config_path)

# Read in CLC and HBPC data frames
# Read in data
cat("\n\n--- ReadingData\n")
clc_filename <- file.path(input_dir,"clc.csv")
hbpc_filename <- file.path(input_dir,"hbpc.csv")
clc_inpath <- input_args[['clc']]
if(!is.null(clc_inpath) || clc_inpath != ''){
df_clc <- read_clc_data(input_args[['clc']])
}

df_hbpc <- read_hbpc_data(hbpc_filename)
df_clc <- read_clc_data(clc_filename)
hbpc_inpath <- input_args[['hbpc']]
if(!is.null(hbpc_inpath) || hbpc_inpath != ''){
df_hbpc <- read_hbpc_data(hbpc_inpath)
}

# Process Data
# Process data
if(!is.null(df_hbpc)){
hbpc_df_list <- process_data(df_hbpc, envir=GOCC$HBPC)
report_all(hbpc_df_list, GOCC$HBPC, config, output_dir)
}else{
cat(paste("\nHBPC input file", hbpc_filename, "not present or malformed.\n"))
cat(paste("\nHBPC input file", hbpc_inpath, "not present or malformed.\n"))
hbpc_df_list <- list()
}

if(!is.null(df_clc)){
clc_df_list <- process_data(df_clc, envir=GOCC$CLC)
report_all(clc_df_list, GOCC$CLC, config, output_dir)
}else{
cat(paste("\nCLC input file", clc_filename, "not present or malformed.\n"))
cat(paste("\nCLC input file", clc_inpath, "not present or malformed.\n"))
clc_df_list <- list()
}

report_all(hbpc_df_list, GOCC$HBPC, config, output_dir)
report_all(clc_df_list, GOCC$CLC, config, output_dir)

cat("\n\nEnd of Line\n\n")
}
74 changes: 0 additions & 74 deletions bin/build_reports.sh

This file was deleted.

76 changes: 0 additions & 76 deletions bin/generate_example_data.sh

This file was deleted.

46 changes: 25 additions & 21 deletions bin/gocc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,18 @@ command -v Rscript 1> /dev/null 2>&1 || \
read -r -d '' USE_MSG <<'HEREDOC'
Usage:
gocc.sh -h
gocc.sh input_dir config_file
gocc.sh -i [path to input dir] -c [path to config]
gocc.sh --input [path to input dir] --config [path to config]
gocc.sh [options]
gocc.sh [options] config_file
Input directory is expected to contain hbpc.csv and clc.csv files.
Options:
-h | --help print help and exit
-i | --input path to input directory
-c | --config path to configuration file
-o | --output path to output directory
--clc path to clc report input csv file
--hbpc path to hbpc report input csv file
--dementia (unimplimented) path to dementia report input csv file
HEREDOC

# Parse args
Expand All @@ -29,10 +30,6 @@ while (( "$#" )); do
echo "${USE_MSG}"
exit 0
;;
-i|--input)
INPUT_DIR=$2
shift 2
;;
-c|--config)
CONFIG_FILE=$2
shift 2
Expand All @@ -41,6 +38,18 @@ while (( "$#" )); do
OUTPUT_DIR=$2
shift 2
;;
--clc)
CLC_INPUT=$2
shift 2
;;
--hbpc)
HBPC_INPUT=$2
shift 2
;;
--dementia)
DEMENTIA_INPUT=$2
shift 2
;;
--) # end argument parsing
shift
break
Expand All @@ -56,23 +65,16 @@ while (( "$#" )); do
esac
done

# Sort out input directory and shift params if used
if [[ -z $INPUT_DIR ]]; then
if [[ ${PARAMS[0]} ]]; then
INPUT_DIR="${PARAMS[0]}"
PARAMS=("${PARAMS[@]:1}")
else
echo "Aborting: Input directory required."
exit 1
fi
# Check for input options
if [[ -z ${CLC_INPUT} ]] && [[ -z ${HBPC_INPUT} ]] && [[ -z ${DEMENTIA_INPUT} ]]; then
echo "Aborting: Report input file required. See -h for input options."
exit 1
fi

# Sort out config file.
# Check 2nd param (unshifted case) then 1st param (shifted case)
if [[ -z $CONFIG_FILE ]]; then
if [[ ${PARAMS[1]} ]]; then
CONFIG_FILE="${PARAMS[1]}"
elif [[ ${PARAMS[0]} ]]; then
if [[ ${PARAMS[0]} ]]; then
CONFIG_FILE="${PARAMS[0]}"
else
echo "Aborting: Config file required."
Expand All @@ -87,8 +89,10 @@ fi
echo "Creating ${OUTPUT_DIR} if it doesn't exist"
mkdir -p "${OUTPUT_DIR}"

INPUT_ARGS="clc='${CLC_INPUT}', hbpc='${HBPC_INPUT}', dementia='${DEMENTIA_INPUT}'"

echo "Running GoCC R Package."
EXPR="gocc::main('${INPUT_DIR}', '${CONFIG_FILE}', '${OUTPUT_DIR}')"
EXPR="gocc::main(config_path='${CONFIG_FILE}', output_dir='${OUTPUT_DIR}', ${INPUT_ARGS})"
echo "${EXPR}"
Rscript --vanilla --default-packages=gocc -e "${EXPR}"

Expand Down
62 changes: 0 additions & 62 deletions bin/install_required_packages.r

This file was deleted.

Loading

0 comments on commit 11e9a24

Please sign in to comment.