Skip to content

Commit fd376c7

Browse files
now returns silently
1 parent 35e39c9 commit fd376c7

4 files changed

Lines changed: 54 additions & 30 deletions

File tree

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Add function to extract family tree from wiki family tree template
55
* Add tests for readWikifamilytree
66
* Create vignette for adjacency matrix methods
7+
* Silences invisible list for plot
78

89
# BGmisc 1.3.4.1
910
* Hot fix to resolve issue with list of adjacency matrix not loading saved version

R/plotPedigree.R

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ plotPedigree <- function(ped,
109109

110110
# Ensure the output is reverted back to console when function exits
111111
# on.exit(if (sink.number() > 0) sink(), add = TRUE)
112-
112+
if (verbose) {
113113
plot_picture <- kinship2::plot.pedigree(p3,
114114
cex = cex,
115115
col = col,
@@ -120,15 +120,35 @@ plotPedigree <- function(ped,
120120
density = density,
121121
angle = angle, keep.par = keep.par,
122122
pconnect = pconnect,
123-
mar = mar
123+
mar = mar,
124+
...
124125
)
125126

126127
# Explicitly revert the standard output back to the console
127128
# if (sink.number() > 0) {
128129
# sink()
129130
# }
131+
return(plot_picture)
132+
}else{
133+
plot_picture <- suppressMessages(kinship2::plot.pedigree(p3,
134+
cex = cex,
135+
col = col,
136+
symbolsize = symbolsize,
137+
branch = branch,
138+
packed = packed, align = align,
139+
width = width,
140+
density = density,
141+
angle = angle, keep.par = keep.par,
142+
pconnect = pconnect,
143+
mar = mar,
144+
...
145+
))
130146

147+
plot_picture[c("plist", "x", "y", "boxw", "boxh","call")] <- NULL
148+
class(plot_picture) <- NULL
131149
return(plot_picture)
150+
}
151+
132152
}
133153
} else {
134154
stop("The structure of the provided pedigree data does not match the expected structure.")

tests/testthat/test-plotPedigree.R

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
test_that("simulated pedigree plots correctly", {
2+
set.seed(5)
3+
Ngen <- 4
4+
kpc <- 4
5+
sexR <- .50
6+
marR <- .7
7+
8+
results <- simulatePedigree(kpc = kpc, Ngen = Ngen, sexR = sexR, marR = marR)
9+
10+
expect_no_error(plotPedigree(results, verbose = FALSE))
11+
12+
kpc <- 2
13+
results2 <- simulatePedigree(kpc = kpc, Ngen = Ngen, sexR = sexR, marR = marR)
14+
results2$fam <- paste0("fam 2")
15+
results <- rbind(results, results2)
16+
expect_output(plotPedigree(results, verbose = TRUE))
17+
})
18+
19+
20+
test_that("pedigree plots correctly with affected variables", {
21+
set.seed(5)
22+
Ngen <- 4
23+
kpc <- 4
24+
sexR <- .50
25+
marR <- .7
26+
27+
results <- simulatePedigree(kpc = kpc, Ngen = Ngen, sexR = sexR, marR = marR)
28+
results$affected <- rbinom(n = nrow(results), size = 1, prob = .1)
29+
expect_output(plotPedigree(results, verbose = TRUE, affected = "affected"))
30+
expect_output(plotPedigree(results, verbose = TRUE, affected = results$affected))
31+
})

tests/testthat/test-simulatePedigree.R

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,6 @@ test_that("simulated pedigree generates expected data structure", {
1717
expect_equal(mean(results$sex == "M"), sexR, tolerance = .05)
1818
})
1919

20-
test_that("simulated pedigree plots correctly", {
21-
set.seed(5)
22-
Ngen <- 4
23-
kpc <- 4
24-
sexR <- .50
25-
marR <- .7
26-
27-
results <- simulatePedigree(kpc = kpc, Ngen = Ngen, sexR = sexR, marR = marR)
28-
expect_no_error(plotPedigree(results, verbose = FALSE))
29-
30-
kpc <- 2
31-
results2 <- simulatePedigree(kpc = kpc, Ngen = Ngen, sexR = sexR, marR = marR)
32-
results2$fam <- paste0("fam 2")
33-
results <- rbind(results, results2)
34-
expect_output(plotPedigree(results, verbose = TRUE))
35-
})
3620

3721
test_that("simulatePedigree verbose prints updates", {
3822
set.seed(5)
@@ -44,15 +28,3 @@ test_that("simulatePedigree verbose prints updates", {
4428
expect_output(simulatePedigree(kpc = kpc, Ngen = Ngen, sexR = sexR, marR = marR, verbose = TRUE), regexp = "Let's build the connection within each generation first")
4529
})
4630

47-
test_that("pedigree plots correctly with affected variables", {
48-
set.seed(5)
49-
Ngen <- 4
50-
kpc <- 4
51-
sexR <- .50
52-
marR <- .7
53-
54-
results <- simulatePedigree(kpc = kpc, Ngen = Ngen, sexR = sexR, marR = marR)
55-
results$affected <- rbinom(n = nrow(results), size = 1, prob = .1)
56-
expect_output(plotPedigree(results, verbose = TRUE, affected = "affected"))
57-
expect_output(plotPedigree(results, verbose = TRUE, affected = results$affected))
58-
})

0 commit comments

Comments
 (0)