Skip to content

Commit

Permalink
Merge pull request #570 from conig/devel
Browse files Browse the repository at this point in the history
Ensure generate_author_yml retains affiliation order by person
  • Loading branch information
crsh committed Oct 6, 2023
2 parents 27715f1 + 850fa10 commit f17599f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
3 changes: 2 additions & 1 deletion R/generate_author_yml.R
Expand Up @@ -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(
Expand Down
5 changes: 4 additions & 1 deletion 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

Expand Down
24 changes: 24 additions & 0 deletions tests/testthat/test-generate_author_yml.R
Expand Up @@ -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)

})

0 comments on commit f17599f

Please sign in to comment.