Skip to content

Commit b6e3356

Browse files
Fix style and maintainability issues in simulatePedigree.R (#134)
* Initial plan * Fix 2 maintainability, 5 style issues in R/simulatePedigree.R Co-authored-by: smasongarrison <6001608+smasongarrison@users.noreply.github.com> * Remove unreachable else-if branches to improve patch coverage Co-authored-by: smasongarrison <6001608+smasongarrison@users.noreply.github.com> * Rename Rd to buildBtwnGenerations; delete images Rename man/buildBetweenGenerations.Rd to man/buildBtwnGenerations.Rd and update the Rd metadata (\name, \alias, and usage) to reflect the new function name. Remove three generated vignette figure PNGs (v5_ASOIAF_files/figure-html/unnamed-chunk-5-1/2/3.png) that were previously checked into the repo and can be regenerated by the vignette build. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: smasongarrison <6001608+smasongarrison@users.noreply.github.com> Co-authored-by: Mason Garrison <garrissm@wfu.edu>
1 parent 56d369c commit b6e3356

2 files changed

Lines changed: 13 additions & 23 deletions

File tree

R/simulatePedigree.R

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#' as well as assigning unique couple IDs. It does not return a value explicitly.
2323
#'
2424

25-
buildBetweenGenerations <- function(df_Fam, Ngen, sizeGens, verbose = FALSE, marR, sexR, kpc,
25+
buildBtwnGenerations <- function(df_Fam, Ngen, sizeGens, verbose = FALSE, marR, sexR, kpc,
2626
rd_kpc, personID = "ID",
2727
momID = "momID",
2828
dadID = "dadID",
@@ -41,7 +41,7 @@ buildBetweenGenerations <- function(df_Fam, Ngen, sizeGens, verbose = FALSE, mar
4141
}
4242

4343
if (use_optimized) {
44-
df_Fam <- buildBetweenGenerations_optimized(
44+
df_Fam <- buildBtwnGenerations_opt(
4545
df_Fam = df_Fam,
4646
Ngen = Ngen,
4747
sizeGens = sizeGens,
@@ -58,7 +58,7 @@ buildBetweenGenerations <- function(df_Fam, Ngen, sizeGens, verbose = FALSE, mar
5858
beta = TRUE
5959
)
6060
} else {
61-
df_Fam <- buildBetweenGenerations_base(
61+
df_Fam <- buildBtwnGenerations_base(
6262
df_Fam = df_Fam,
6363
Ngen = Ngen,
6464
sizeGens = sizeGens,
@@ -75,11 +75,11 @@ buildBetweenGenerations <- function(df_Fam, Ngen, sizeGens, verbose = FALSE, mar
7575
beta = FALSE
7676
)
7777
}
78-
return(df_Fam)
78+
df_Fam
7979
}
8080

8181

82-
buildBetweenGenerations_base <- function(df_Fam,
82+
buildBtwnGenerations_base <- function(df_Fam,
8383
Ngen,
8484
sizeGens,
8585
verbose = FALSE,
@@ -360,15 +360,10 @@ buildBetweenGenerations_base <- function(df_Fam,
360360

361361
# Align lengths between couples and random_numbers.
362362
# If random_numbers is longer than couples, truncate random_numbers.
363-
# If random_numbers is shorter than couples, drop extra couples.
364363
nCouples <- length(parent_rows)
365364

366365
if (length(random_numbers) > nCouples) {
367366
random_numbers <- random_numbers[seq_len(nCouples)]
368-
} else if (length(random_numbers) < nCouples) {
369-
keep <- seq_len(length(random_numbers))
370-
ma_ids <- ma_ids[keep]
371-
pa_ids <- pa_ids[keep]
372367
}
373368

374369
# Expand from "one mother/father per couple" to "one mother/father per child".
@@ -455,10 +450,10 @@ buildBetweenGenerations_base <- function(df_Fam,
455450
}
456451
}
457452
}
458-
return(df_Fam)
453+
df_Fam
459454
}
460455

461-
buildBetweenGenerations_optimized <- function(df_Fam,
456+
buildBtwnGenerations_opt <- function(df_Fam,
462457
Ngen,
463458
sizeGens,
464459
verbose = FALSE,
@@ -743,15 +738,10 @@ buildBetweenGenerations_optimized <- function(df_Fam,
743738

744739
# Align lengths between couples and random_numbers.
745740
# If random_numbers is longer than couples, truncate random_numbers.
746-
# If random_numbers is shorter than couples, drop extra couples.
747741
nCouples <- length(parent_rows)
748742

749743
if (length(random_numbers) > nCouples) {
750744
random_numbers <- random_numbers[seq_len(nCouples)]
751-
} else if (length(random_numbers) < nCouples) {
752-
keep <- seq_len(length(random_numbers))
753-
ma_ids <- ma_ids[keep]
754-
pa_ids <- pa_ids[keep]
755745
}
756746

757747
# Expand from "one mother/father per couple" to "one mother/father per child".
@@ -838,7 +828,7 @@ buildBetweenGenerations_optimized <- function(df_Fam,
838828
}
839829
}
840830
}
841-
return(df_Fam)
831+
df_Fam
842832
}
843833

844834
#' Simulate Pedigrees
@@ -956,7 +946,7 @@ simulatePedigree <- function(kpc = 3,
956946
)
957947
}
958948

959-
df_Fam <- buildBetweenGenerations(
949+
df_Fam <- buildBtwnGenerations(
960950
df_Fam = df_Fam,
961951
Ngen = Ngen,
962952
sizeGens = sizeGens,
@@ -981,7 +971,7 @@ simulatePedigree <- function(kpc = 3,
981971
# connect the detached members
982972
df_Fam[is.na(df_Fam[[momID]]) & is.na(df_Fam[[dadID]]) & df_Fam$gen > 1, ]
983973

984-
return(df_Fam)
974+
df_Fam
985975
}
986976

987977
#' @rdname simulatePedigree
Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)