diff --git a/R/generate_author_yml.R b/R/generate_author_yml.R index 8e3af981..0c68fde9 100644 --- a/R/generate_author_yml.R +++ b/R/generate_author_yml.R @@ -73,7 +73,8 @@ generate_author_yml <- function( ) authors <- sapply(seq_along(researchers), function(i) { - i_affil = paste(affil_numeric[affil_order %in% unlist(researchers[i])], collapse = ",") + i_affil <- affil_numeric[match(unlist(researchers[i]), names(affil_numeric))] + i_affil <- paste(i_affil, collapse = ",") if (names(researchers)[i] == corres_name) { extra <- as.character( diff --git a/inst/NEWS.md b/inst/NEWS.md index c18c1575..4754f1bc 100644 --- a/inst/NEWS.md +++ b/inst/NEWS.md @@ -1,8 +1,11 @@ - # Upcoming release - For ANOVA methods, *MSE*s are again returned if requested by the user (reported by @Sashpta, [#562](https://github.com/crsh/papaja/issues/562)). The global default for reporting *MSE*s now depends on the [**effectsize**](https://CRAN.r-project.org/package=effectsize) package: If **effectsize** is installed, the default for reporting *MSE*s is `FALSE`, if **effectsize** is not installed, the default is `TRUE`. +### Existing functions + +- `generate_author_yml()` + - Now preserves affiliation order for each author (see #569). # papaja 0.1.2 diff --git a/tests/testthat/test-generate_author_yml.R b/tests/testthat/test-generate_author_yml.R index 98e0c6a7..4c831f46 100644 --- a/tests/testthat/test-generate_author_yml.R +++ b/tests/testthat/test-generate_author_yml.R @@ -128,3 +128,27 @@ test_that("generate_author_yml enforces unique authors/affiliations", { ) }) + +test_that("generate_author_yml preserves affiliation order", { + + text <- generate_author_yml( + researchers = list( + "James H. Conigrave" = c("IPPE", "UQ"), + "Michael Noetel" = c("UQ", "IPPE") + ), + affiliations = list("IPPE" = "Institute for Postitive Psychology and Education", + "UQ" = "University of Queensland"), + corres_email = "james@conigrave.com", + corres_address = "33 Berry Street, North Sydney, NSW, Australia", + corres_name = "James H. Conigrave" + ) + + matches <- gregexpr("(?<=affiliation : \")\\d+(,\\d+)*", text, perl=TRUE) + + all_affiliations <- regmatches(text, matches)[[1]] + + # Get the second instance + second_affiliation <- all_affiliations[2] + expect_equal("2,1", second_affiliation) + +})