Closed kylebaron closed 4 years ago
library(tidyverse) library(haven) library(yspec)
spec <- ys_load("../data/spec/analysis1.yml")
library(tidyverse)
sp <-spec
nm_input2 <- function(sp, right = FALSE) { comment <- pull_meta(sp, "comment_col") char <- map_chr(sp, "type") == "character" col <- map_chr(sp, "col") drop <- ifelse(char & col != comment, "=DROP", "") col <- paste0(col,drop) sh <- ys_get_short(sp) %>% unlist u <- ys_get_unit(sp, parens = TRUE) %>% unlist mx <- max(nchar(col)) fl <- ifelse(right, "", "-") col <- formatC(col, width = mx, flag = fl)
rhs <- paste(sh,u)
co <- map_chr(spec, yspec:::pack_codes) co[char] <- "" append <- nchar(co) > 0 sp <- paste0(rep(" ", times = mx),collapse = "") co <- ifelse( append, paste0(rhs, "\n", paste0(sp," ; ",unname(co))), rhs ) input <- c("$INPUT", paste(col, ";",co)) cat(input, sep = "\n") }
nm_input <- function(sp, right = FALSE) { comment <- pull_meta(sp, "comment_col") char <- map_chr(sp, "type") == "character" col <- map_chr(sp, "col") drop <- ifelse(char & col != comment, "=DROP", "") col <- paste0(col,drop) sh <- ys_get_short(sp) %>% unlist u <- ys_get_unit(sp, parens = TRUE) %>% unlist mx <- max(nchar(col)) fl <- ifelse(right, "", "-") col <- formatC(col, width = mx, flag = fl)
input <- c("$INPUT", paste(col, ";",sh,u))
co <- map_chr(spec, yspec:::pack_codes) co <- co[co!="" & !char] co <- gsub("values: ", "", co)
col <- formatC(names(co), width = mx-1, flag = "-") co <- paste0("; ", col, ": ", co)
cat(input, sep = "\n") cat("\n; DECODE ---------------- \n") cat(co, sep = "\n") }
nm_input(spec)
nm_input2(spec)
data <- read_csv("../data/derived/analysis1.csv")
data <- select(data, names(spec))
ys_check(data,spec)
ys_document( spec, output_dir = "../data/derived", build_dir = mrgtemplate(), author = "Angie Merkel, PhD", output_file = "analysis1.pdf", format = "x_table_2" )
data <- ys_add_labels(data,spec)
haven::write_xpt( data, path = "../data/derived/analysis1.xpt", name = "analysis", version = 5 )
ae <- ys_load("../data/spec/analysis_ae.yml")
project <- ys_project(spec, ae)
ys_document( project, type = 'regulatory', output_dir = "../data/derived", build_dir = mrgtemplate() )
Closing; this was just holding text.
'
' Purpose: assemble the analysis1 data set; write xpt and define files
' Author: Kyle Baron
'
library(tidyverse) library(haven) library(yspec)
spec <- ys_load("../data/spec/analysis1.yml")
library(tidyverse)
sp <-spec
nm_input2 <- function(sp, right = FALSE) { comment <- pull_meta(sp, "comment_col") char <- map_chr(sp, "type") == "character" col <- map_chr(sp, "col") drop <- ifelse(char & col != comment, "=DROP", "") col <- paste0(col,drop) sh <- ys_get_short(sp) %>% unlist u <- ys_get_unit(sp, parens = TRUE) %>% unlist mx <- max(nchar(col)) fl <- ifelse(right, "", "-") col <- formatC(col, width = mx, flag = fl)
rhs <- paste(sh,u)
co <- map_chr(spec, yspec:::pack_codes) co[char] <- "" append <- nchar(co) > 0 sp <- paste0(rep(" ", times = mx),collapse = "") co <- ifelse( append, paste0(rhs, "\n", paste0(sp," ; ",unname(co))), rhs ) input <- c("$INPUT", paste(col, ";",co)) cat(input, sep = "\n") }
nm_input <- function(sp, right = FALSE) { comment <- pull_meta(sp, "comment_col") char <- map_chr(sp, "type") == "character" col <- map_chr(sp, "col") drop <- ifelse(char & col != comment, "=DROP", "") col <- paste0(col,drop) sh <- ys_get_short(sp) %>% unlist u <- ys_get_unit(sp, parens = TRUE) %>% unlist mx <- max(nchar(col)) fl <- ifelse(right, "", "-") col <- formatC(col, width = mx, flag = fl)
mx <- max(nchar(sh))
input <- c("$INPUT", paste(col, ";",sh,u))
co <- map_chr(spec, yspec:::pack_codes) co <- co[co!="" & !char] co <- gsub("values: ", "", co)
mx <- max(nchar(names(co)))
col <- formatC(names(co), width = mx-1, flag = "-") co <- paste0("; ", col, ": ", co)
cat(input, sep = "\n") cat("\n; DECODE ---------------- \n") cat(co, sep = "\n") }
nm_input(spec)
nm_input2(spec)
data <- read_csv("../data/derived/analysis1.csv")
data <- select(data, names(spec))
ys_check(data,spec)
ys_document( spec, output_dir = "../data/derived", build_dir = mrgtemplate(), author = "Angie Merkel, PhD", output_file = "analysis1.pdf", format = "x_table_2" )
' Add labels
data <- ys_add_labels(data,spec)
' Write the xpt file
haven::write_xpt( data, path = "../data/derived/analysis1.xpt", name = "analysis", version = 5 )
' Now, do the same thing for the AE data set
ae <- ys_load("../data/spec/analysis_ae.yml")
' Make a project object
'
project <- ys_project(spec, ae)
ys_document( project, type = 'regulatory', output_dir = "../data/derived", build_dir = mrgtemplate() )