From a86255e794da7847c763a99564e9623d96c473ad Mon Sep 17 00:00:00 2001 From: Anton Rasmussen Date: Wed, 31 Jan 2018 19:25:30 +0100 Subject: [PATCH 1/4] make test that shows inconsistent behavior for str_interp printing of list depending on presence of of additional placholder --- tests/testthat/test-interp.r | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/testthat/test-interp.r b/tests/testthat/test-interp.r index f597ddb1..977f4081 100644 --- a/tests/testthat/test-interp.r +++ b/tests/testthat/test-interp.r @@ -68,3 +68,14 @@ 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) +}) From a3214e8b3d71732500748bdd90b687e871341500 Mon Sep 17 00:00:00 2001 From: Anton Rasmussen Date: Wed, 31 Jan 2018 19:35:44 +0100 Subject: [PATCH 2/4] trigger travis --- tests/testthat/test-interp.r | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/testthat/test-interp.r b/tests/testthat/test-interp.r index 977f4081..e911f4dd 100644 --- a/tests/testthat/test-interp.r +++ b/tests/testthat/test-interp.r @@ -73,9 +73,7 @@ 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) }) From afb8656fbc904f7048acc7b23194f555c3813531 Mon Sep 17 00:00:00 2001 From: Anton Rasmussen Date: Wed, 31 Jan 2018 19:43:02 +0100 Subject: [PATCH 3/4] Make eval_interp_matches return more consistent answers by using SIMPLIFY=FALSE in mapply. This should make str_interp behave more consistently when interpolating lists into placeholders. --- R/interp.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 32ec897abe815d121a2841abff206fb12ebe1b72 Mon Sep 17 00:00:00 2001 From: Anton Rasmussen Date: Mon, 28 May 2018 22:27:28 +0200 Subject: [PATCH 4/4] Add item to NEWS.md describing change to str_interp() --- NEWS.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/NEWS.md b/NEWS.md index d208c603..8ef5d953 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,6 @@ +* `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)