Skip to content

Commit 950c3a7

Browse files
committed
Test different sets of PIs per receiver project. Closes #20.
1 parent ea26c56 commit 950c3a7

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

R/project_contacts.R

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ project_contacts <- function(extract, type = c("receiver", "tag")) {
5454
POC = strsplit(contact_poc, " \\(|\\)(, )?")
5555
)]
5656
} else {
57-
pis <- unique(extract, by = c("trackercode"))
57+
pis <- unique(extract, by = c("trackercode", "tag_contact_poc", "tag_contact_pi"))
5858
pis[, ":="(
5959
PI = strsplit(tag_contact_pi, " \\(|\\)(, )?"),
6060
POC = strsplit(tag_contact_poc, " \\(|\\)(, )?")
@@ -99,9 +99,10 @@ project_contacts <- function(extract, type = c("receiver", "tag")) {
9999
),
100100
by = "trackercode"
101101
]
102-
pis <- merge(pis[, -c("PI", "POC", "PI_emails", "POC_emails")],
102+
pis <- merge(
103+
pis[, -c("PI", "POC", "PI_emails", "POC_emails")],
103104
pi_key,
104-
on = "trackercode"
105+
by = "trackercode"
105106
)
106107
pis <- unique(pis, by = "trackercode")
107108
}

tests/testthat/test-project_contacts.R

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,16 +127,41 @@ test_that("Multiple sets of tag PIs per project are summarized", {
127127

128128
expect_match(
129129
pi_table[pi_table$project_name == "HFX",]$PI,
130-
"Matthew Apostle, Mary Mother, Dave Hebert, Fred Whoriskey"
130+
"Matthew Apostle, Mary Mother, Dave Hebert, Fred Whoriskey",
131+
fixed = TRUE
131132
)
132133

133134
expect_match(
134135
pi_table[pi_table$project_name == "HFX",]$PI_emails,
135-
"matt@bible,mary@bible,david.hebert@dfo-mpo.gc.ca,fwhoriskey@dal.ca"
136+
"matt@bible,mary@bible,david.hebert@dfo-mpo.gc.ca,fwhoriskey@dal.ca",
137+
fixed = TRUE
136138
)
137139

138140
})
139141

140142
test_that("Multiple sets of receiver PIs per project are summarized", {
143+
qual_multiple_pis <- qualified
144+
qual_multiple_pis[qual_multiple_pis$trackercode == 'TAG',][1, 'tag_contact_pi'] <-
145+
c("Matthew Apostle (matt@bible), Mary Mother (mary@bible)")
146+
147+
pi_table <- project_contacts(qual_multiple_pis, "receiver")
148+
149+
expect_false(
150+
any(
151+
duplicated(pi_table$project_name)
152+
)
153+
)
154+
155+
expect_match(
156+
pi_table[pi_table$project_name == "TAG",]$PI,
157+
"Matthew Apostle, Mary Mother, Barbara Block",
158+
fixed = TRUE
159+
)
160+
161+
expect_match(
162+
pi_table[pi_table$project_name == "TAG",]$PI_emails,
163+
"matt@bible,mary@bible,bblock@stanford.edu",
164+
fixed = TRUE
165+
)
141166

142167
})

0 commit comments

Comments
 (0)