Re: [Rd] eval(parse()) within mutate() returning same value for all rows

2023-12-30 Thread Gabor Grothendieck
Here is a solution that does not hard code 3: library(dplyr) library(purrr) library(tidyr) df %>% separate_wider_delim(args, ",", names_sep = "") %>% mutate(combined = exec(sprintf, .[[1]], !!!.[-1])) ## # A tibble: 3 × 5 ## wordsargs1 args2 args3 combined

Re: [Rd] eval(parse()) within mutate() returning same value for all rows

2023-12-29 Thread Dirk Eddelbuettel
On 29 December 2023 at 22:31, Mateo Obregón wrote: | Thanks Gabor, I like your solution that splits the args into separate columns, | in turn making the sprintf() call more interpretable . Well you may also like `tstrsplit()`, a gem inside data.table: > suppressMessages(library(data.table))

Re: [Rd] eval(parse()) within mutate() returning same value for all rows

2023-12-29 Thread Mateo Obregón
Thanks Gabor, I like your solution that splits the args into separate columns, in turn making the sprintf() call more interpretable . Cheers. Mateo. -- Mateo Obregón On Friday, 29 December 2023 18:45:06 GMT Gabor Grothendieck wrote: > If the question is how to accomplish this as opposed to

Re: [Rd] eval(parse()) within mutate() returning same value for all rows

2023-12-29 Thread Gabor Grothendieck
If the question is how to accomplish this as opposed to how to use eval then we can do it without eval like this provided we can assume that words contains three %s . library(dplyr) library(tidyr) df <- tibble(words=c("%s plus %s equals %s"),args=c("1,1,2","2,2,4","3,3,6")) df |>

Re: [Rd] eval(parse()) within mutate() returning same value for all rows

2023-12-29 Thread Duncan Murdoch
On 29/12/2023 9:13 a.m., Mateo Obregón wrote: Hi all- Looking through stackoverflow for R string combining examples, I found the following from 3 years ago: The top answer suggests to use

Re: [Rd] eval(parse()) within mutate() returning same value for all rows

2023-12-29 Thread Mateo Obregón
Thanks Dirk for your response. The "base" R code is just too unwieldy to be easily understandable. The eval(parse(sprintf())) solution provided is ungainly too, but at least its more understandable from a casual reading of it. I'll punt this case over to the dplyr people then. Cheers. Mateo.

Re: [Rd] eval(parse()) within mutate() returning same value for all rows

2023-12-29 Thread Jan Gorecki
Unless you are able to reproduce the problem without dplyr then you should submit your question to dplyr issues tracker. R-devel is for issues in R, not in a third party packages. On Fri, Dec 29, 2023, 15:13 Mateo Obregón wrote: > Hi all- > > Looking through stackoverflow for R string combining

Re: [Rd] eval(parse()) within mutate() returning same value for all rows

2023-12-29 Thread Dirk Eddelbuettel
On 29 December 2023 at 14:13, Mateo Obregón wrote: | Hi all- | | Looking through stackoverflow for R string combining examples, I found the | following from 3 years ago: | | | | The top

[Rd] eval(parse()) within mutate() returning same value for all rows

2023-12-29 Thread Mateo Obregón
Hi all- Looking through stackoverflow for R string combining examples, I found the following from 3 years ago: The top answer suggests to use eval(parse(sprintf())). I tried the suggestion