diff --git a/NEWS.md b/NEWS.md index be5f5525..1cf6e029 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,8 @@ # stringr 1.3.1.9000 +* `str_interp()` now renders lists consistently independent on the presence of + additional placeholders (@amhrasmussen) + # stringr 1.3.1 * `str_replace_all()` with a named vector now respects modifier functions (#207) diff --git a/R/interp.R b/R/interp.R index a6edae59..e02f9948 100644 --- a/R/interp.R +++ b/R/interp.R @@ -143,7 +143,7 @@ eval_interp_matches <- function(matches, env) { formats <- extract_formats(matches) # Format the values and return. - mapply(sprintf, formats, values) + mapply(sprintf, formats, values, SIMPLIFY = FALSE) } #' Extract Expression Objects from String Interpolation Matches diff --git a/tests/testthat/test-interp.r b/tests/testthat/test-interp.r index f597ddb1..e911f4dd 100644 --- a/tests/testthat/test-interp.r +++ b/tests/testthat/test-interp.r @@ -68,3 +68,12 @@ test_that("str_interp fails when encountering nested placeholders", { test_that("str_interp fails when input is not a character string", { expect_error(str_interp(3L)) }) + +test_that("str_interp formats list independetly of other placeholders", { + a_list <- c("item1", "item2", "item3") + other <- "1" + extract <- function(text) regmatches(text, regexpr("xx[^x]+xx", text)) + from_list <- extract(str_interp("list: xx${a_list}xx")) + from_both <- extract(str_interp("list: xx${a_list}xx, and another ${other}")) + expect_equal(from_list, from_both) +})