Skip to content

Commit 9dfb3a4

Browse files
Update readGedcom.R
subfactor
1 parent d023b78 commit 9dfb3a4

1 file changed

Lines changed: 52 additions & 17 deletions

File tree

R/readGedcom.R

Lines changed: 52 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ readGedcom <- function(file_path,
5555
combine_cols = TRUE,
5656
skinny = FALSE,
5757
update_rate = 1000,
58+
post_process = TRUE,
5859
...) {
5960
# Checks
6061
if (!file.exists(file_path)) stop("File does not exist: ", file_path)
@@ -300,6 +301,39 @@ readGedcom <- function(file_path,
300301
if (nrow(df_temp) != num_rows$num_indi_rows) {
301302
warning("The number of people found in the processed file does not match the number of individuals raw data")
302303
}
304+
305+
if(post_process){
306+
if (verbose) {
307+
print("Post-processing data frame")
308+
}
309+
# Remove the first row (empty)
310+
df_temp <- postProcessGedcom(
311+
df_temp = df_temp,
312+
remove_empty_cols = remove_empty_cols,
313+
combine_cols = combine_cols,
314+
add_parents = add_parents,
315+
skinny = skinny,
316+
verbose = verbose
317+
)
318+
319+
}
320+
321+
return(df_temp)
322+
}
323+
324+
#' Post-process GEDCOM Data Frame
325+
#'
326+
#' @inheritParams readGedcom
327+
#' @inheritParams mapFAMS2parents
328+
#' @return A data frame with processed information.
329+
330+
postProcessGedcom <- function(df_temp,
331+
remove_empty_cols = TRUE,
332+
combine_cols = TRUE,
333+
add_parents = TRUE,
334+
skinny = TRUE,
335+
verbose = FALSE
336+
){
303337
# Add mom and dad ids
304338
if (add_parents) {
305339
if (verbose) {
@@ -308,28 +342,29 @@ readGedcom <- function(file_path,
308342
df_temp <- processParents(df_temp, datasource = "gedcom")
309343
}
310344

311-
if (combine_cols) {
312-
df_temp <- collapseNames(verbose = verbose, df_temp = df_temp)
313-
}
345+
if (combine_cols) {
346+
df_temp <- collapseNames(verbose = verbose, df_temp = df_temp)
347+
}
314348

315-
if (remove_empty_cols) {
316-
# Remove empty columns
317-
if (verbose) {
318-
print("Removing empty columns")
319-
}
320-
df_temp <- df_temp[, colSums(is.na(df_temp)) < nrow(df_temp)]
349+
if (remove_empty_cols) {
350+
# Remove empty columns
351+
if (verbose) {
352+
print("Removing empty columns")
321353
}
322-
if (skinny) {
323-
if (verbose) {
324-
print("Slimming down the data frame")
325-
}
326-
df_temp <- df_temp[, colSums(is.na(df_temp)) < nrow(df_temp)]
327-
df_temp$FAMC <- NULL
328-
df_temp$FAMS <- NULL
354+
df_temp <- df_temp[, colSums(is.na(df_temp)) < nrow(df_temp)]
355+
}
356+
if (skinny) {
357+
if (verbose) {
358+
print("Slimming down the data frame")
329359
}
330-
return(df_temp)
360+
df_temp <- df_temp[, colSums(is.na(df_temp)) < nrow(df_temp)]
361+
df_temp$FAMC <- NULL
362+
df_temp$FAMS <- NULL
331363
}
332364

365+
return(df_temp)
366+
367+
}
333368

334369
#' Create a mapping of family IDs to parent IDs
335370
#'

0 commit comments

Comments
 (0)