Skip to content

Commit

Permalink
stargin 97 metadata and import
Browse files Browse the repository at this point in the history
See #3
  • Loading branch information
wibeasley committed Jan 12, 2018
1 parent 4c2d305 commit bab5ee3
Show file tree
Hide file tree
Showing 18 changed files with 960 additions and 28 deletions.
52 changes: 52 additions & 0 deletions dal/flow-97.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# This is a hack of https://github.com/OuhscBbmc/miechv-3/blob/master/manipulation/osdh/osdh-flow.R
# That file runs everything (those dozens of files) dynamically.
# This one is hard-coded, and requires one manual stop (to run the C#).
# But since there are so few files, I think it's an acceptable compromise.

rm(list=ls(all=TRUE)) #Clear the memory for any variables set from any previous runs.

# ---- load-sources ------------------------------------------------------------


# ---- load-packages -----------------------------------------------------------
library(magrittr)
requireNamespace("testit")

# ---- declare-globals ---------------------------------------------------------
path_sources <- c(
# 97
"dal/import-97-metadata.R",
"dal/import-97-raw.R",
"dal/outcomes/outcomes-97.R"
)

file.exists(path_sources)
all_sources_exist <- path_sources %>%
purrr::map_lgl(file.exists) %>%
all()
if( !all_sources_exist ) stop("All source files to be run should exist.")


# ---- load-data ---------------------------------------------------------------

# ---- tweak-data --------------------------------------------------------------

# ---- run-sources -------------------------------------------------------------

message("Preparing to run\n\t", paste(path_sources, collapse="\n\t"))

(start_time <- Sys.time())


# dir.create(output="./stitched-output/dal/", recursive=T)
knitr::stitch_rmd(script="./dal/import-97-metadata.R", output="./stitched-output/dal/import-97-metadata.md")
knitr::stitch_rmd(script="./dal/import-97-raw.R", output="./stitched-output/dal/import-97-raw.md")

stop("Now run the C# program, then come back to run the rest of the R scripts.")

knitr::stitch_rmd(script="./dal/outcomes/outcomes-97.R", output="./stitched-output/dal/outcomes/outcomes-97.md") # dir.create("./stitched-output/dal/outcomes/", recursive=T)


message("Completed flow-97 at ", Sys.time(), " (in ", round(elapsed_duration, 2), " mins.)")

# ---- verify-values -----------------------------------------------------------
26 changes: 2 additions & 24 deletions dal/import-79-metadata.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,6 @@ lst_col_types <- list(
Active = readr::col_logical(),
Notes = readr::col_character()
),
# item_97 = readr::cols_only(
# ID = readr::col_integer(),
# Label = readr::col_character(),
# MinValue = readr::col_integer(),
# MinNonnegative = readr::col_integer(),
# MaxValue = readr::col_integer(),
# Active = readr::col_logical(),
# Notes = readr::col_character()
# ),
LUExtractSource = col_types_minimal,
LUMarkerEvidence = col_types_minimal,
LUGender = col_types_minimal,
Expand Down Expand Up @@ -138,19 +129,6 @@ lst_col_types <- list(
Active = readr::col_integer(),
Notes = readr::col_character()
)
# variable_97 = readr::cols_only(
# # ID = readr::col_integer(),
# VariableCode = readr::col_character(),
# Item = readr::col_integer(),
# Generation = readr::col_integer(),
# ExtractSource = readr::col_integer(),
# SurveySource = readr::col_integer(),
# SurveyYear = readr::col_integer(),
# LoopIndex = readr::col_integer(),
# Translate = readr::col_integer(),
# Active = readr::col_integer(),
# Notes = readr::col_character()
# )
)

col_types_mapping <- readr::cols_only(
Expand Down Expand Up @@ -199,7 +177,7 @@ ds_table
rm(directory_in) # rm(col_types_tulsa)

# ---- tweak-data --------------------------------------------------------------
# OuhscMunge::column_rename_headstart(ds_county) #Spit out columns to help write call ato `dplyr::rename()`.
# OuhscMunge::column_rename_headstart(ds_county) #Spit out columns to help write call to `dplyr::rename()`.

ds_file <- ds_file %>%
dplyr::left_join( ds_mapping, by=c("name"="table_name")) %>%
Expand Down Expand Up @@ -416,4 +394,4 @@ DBI::dbDisconnect(channel); rm(channel)
RODBC::odbcClose(channel_rodbc); rm(channel_rodbc)

duration_in_seconds <- round(as.numeric(difftime(Sys.time(), start_time, units="secs")))
cat("File completed by `", Sys.info()["user"], "` at ", strftime(Sys.time(), "%Y-%m-%d, %H:%M %z"), " in ", duration_in_seconds, " seconds.", sep="")
cat("`import-79-metadata.R` file completed by `", Sys.info()["user"], "` at ", strftime(Sys.time(), "%Y-%m-%d, %H:%M %z"), " in ", duration_in_seconds, " seconds.", sep="")
Loading

0 comments on commit bab5ee3

Please sign in to comment.