From bd1aa4a5767a0ae0fe867f225e4ef6605c174949 Mon Sep 17 00:00:00 2001 From: mariusbarth Date: Wed, 27 Sep 2023 17:57:46 +0200 Subject: [PATCH 1/3] use safer file paths in generate_author_yml() tests --- tests/testthat/test-generate_author_yml.R | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/tests/testthat/test-generate_author_yml.R b/tests/testthat/test-generate_author_yml.R index db09947c..98e0c6a7 100644 --- a/tests/testthat/test-generate_author_yml.R +++ b/tests/testthat/test-generate_author_yml.R @@ -42,29 +42,28 @@ test_that( rmd <- paste(rmd, collapse = "\n") - input_path <- tempfile(fileext = ".Rmd") - write(rmd, file = input_path) + input_file <- tempfile(fileext = ".Rmd") + write(rmd, file = input_file) - output_path <- tempfile(fileext = ".pdf") + output_file <- gsub(input_file, pattern = "\\.Rmd$", replacement = ".pdf") suppressWarnings( try( capture.output( rmarkdown::render( - input = input_path, - output_file = output_path, - quiet = TRUE, + input = input_file, + quiet = TRUE ) ) , silent = TRUE ) ) - expect_true(file.exists(output_path)) + expect_true(file.exists(output_file)) # Clean up - file.remove(input_path) - file.remove(output_path) + file.remove(input_file) + file.remove(output_file) } ) From b08b8f9661df4cfcb4a947513c4ddb826063aa25 Mon Sep 17 00:00:00 2001 From: James Conigrave <12742211+conig@users.noreply.github.com> Date: Wed, 4 Oct 2023 09:35:35 +1100 Subject: [PATCH 2/3] Ensure affiliations retain listed order for each person. --- R/generate_author_yml.R | 3 ++- tests/testthat/test-generate_author_yml.R | 24 +++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) 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/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) + +}) From 8d2d77027a04a92ed5ab9194019261a225a0a365 Mon Sep 17 00:00:00 2001 From: James Conigrave <12742211+conig@users.noreply.github.com> Date: Fri, 6 Oct 2023 09:20:39 +1100 Subject: [PATCH 3/3] Update news to flag issue #569 fixed. --- inst/NEWS.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/inst/NEWS.md b/inst/NEWS.md index e13a7636..5d7ea47c 100644 --- a/inst/NEWS.md +++ b/inst/NEWS.md @@ -1,3 +1,10 @@ +# papaja 0.1.1.9001 + +### Existing functions + +- `generate_author_yml()` + - Now preserves affiliation order for each author (see #569). + # papaja 0.1.1 - Maintenance update: Adjuted unit tests to avoid removal from CRAN