Skip to content

Commit

Permalink
Merge pull request #72 from istallworthy/run-through
Browse files Browse the repository at this point in the history
data type checking
  • Loading branch information
istallworthy authored Sep 15, 2023
2 parents 4297b78 + af794a5 commit c79f41d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
14 changes: 11 additions & 3 deletions R/inspectData.R
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ inspectData <- function(data, home_dir, exposure, exposure_time_pts, outcome, tv
}


if(!inherits(data, data.frame)){
if(!inherits(data, "data.frame")){
warning(paste0("Your data is a ", class(data), ". Convert to data frame before running devMSMs."),
call. = FALSE)
}
Expand All @@ -147,8 +147,16 @@ inspectData <- function(data, home_dir, exposure, exposure_time_pts, outcome, tv
"numeric"), "continuous", "binary")

# Data type
cat("Please inspect the following table of data types to ensure they are correct for each variable:")
print(str(data))
cat("The following variables are designated as numeric:", "\n")
print(paste(colnames(data)[sapply(data, class) == "numeric"], sep = ",", collapse = ", "))

cat("The following variables are designated as factors:", "\n")
print(paste(colnames(data)[sapply(data, class) == "factor"], sep = ",", collapse = ", "))

oth <- data.frame(variable = names(sapply(data, class)) [!sapply(data, class) %in% c("numeric", "factor")],
type = sapply(data, class) [!sapply(data, class) %in% c("numeric", "factor")])
cat(knitr::kable(oth, caption = "Other variable types",
format = 'pipe'), sep = "\n")


# Exposure summary
Expand Down
2 changes: 1 addition & 1 deletion examplePipelineRevised.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ data <- read.csv("/Users/isabella/Library/CloudStorage/Box-Box/BSL General/MSMs/
data <- as.data.frame(data)
library(dplyr)
data_df <- data_mids[[1]]
data_df <- complete(data_mids, 1)
data_df <- data_df %>% dplyr::select(-c(contains(c(":", "Childhood", "Infancy", "Toddlerhood", "pcx"))))
data <- data_df #single df
Expand Down

0 comments on commit c79f41d

Please sign in to comment.