From 15a5124b65ca5383017be0339c601d77b9f736b6 Mon Sep 17 00:00:00 2001 From: Mason Garrison Date: Mon, 7 Oct 2024 11:45:44 -0400 Subject: [PATCH] Update read-csv-nlsy-79.R --- R/read-csv-nlsy-79.R | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/R/read-csv-nlsy-79.R b/R/read-csv-nlsy-79.R index a46933ac..4fcdf4c9 100644 --- a/R/read-csv-nlsy-79.R +++ b/R/read-csv-nlsy-79.R @@ -29,8 +29,15 @@ #' filePathGen2 <- "~/Nlsy/Datasets/gen2-birth.csv" #' ds <- ReadCsvNlsy79Gen2(filePath = filePathGen2) #' } -ReadCsvNlsy79Gen1 <- function(filePath, - dsExtract = utils::read.csv(filePath)) { +ReadCsvNlsy79Gen1 <- function(filePath = NULL, + dsExtract = NULL) { + if (is.null(dsExtract)) { + if (is.null(filePath)) { + stop("Either 'filePath' or 'dsExtract' must be provided.") + } + dsExtract <- utils::read.csv(filePath) + } + d <- NlsyLinks::SubjectDetails79 if (!("R0000100" %in% colnames(dsExtract))) { @@ -61,9 +68,14 @@ ReadCsvNlsy79Gen1 <- function(filePath, return(ds) } -ReadCsvNlsy79Gen2 <- - function(filePath, - dsExtract = utils::read.csv(filePath)) { +ReadCsvNlsy79Gen2 <- function(filePath = NULL, + dsExtract = NULL) { + if (is.null(dsExtract)) { + if (is.null(filePath)) { + stop("Either 'filePath' or 'dsExtract' must be provided.") + } + dsExtract <- utils::read.csv(filePath) + } d <- NlsyLinks::SubjectDetails79 # dsExtract <- read.csv(filePath) if (!("C0000100" %in% colnames(dsExtract))) {