Questions tagged [r-glue]
76 questions
1
vote
3 answers
Which rlang function should I use to evaluate a glue string as a variable name?
Suppose that I want to create a function to be used within dplyr::mutate(), and in which I feed a variable name, and within the function, it will extract a particular pattern in the variable name given and create a new variable name out of it, like…

Phil
- 7,287
- 3
- 36
- 66
1
vote
2 answers
aligning multi-line `glue` expression
I am using {glue} package to write expressions, which I then parse and display in ggplot2 annotations.
But, if I have a multiline expression, they are not vertically aligned. How can I achieve such an alignment? I thought atop + displaystyle would…

Indrajeet Patil
- 4,673
- 2
- 20
- 51
1
vote
1 answer
Showing variable name in table output when using `modify_caption` in gtsummary with glue packages
I want to write a code that uses dplyr::select(), gtsummary::tbl_summary() and glue::glue().
The plan is:
select a few variables from a dataframe (for example : all numerical variables)
return a table summary based a grouping variable (a factor…

KIM
- 157
- 1
- 1
- 8
1
vote
1 answer
how to interpret the example of package glue for the item "backslashes do need to be doubled"
how to interpret the code below , how R treat and evaluate it and get the result "foo",it is hard to understand for me
`foo}\`` <- "foo"
glue("{
{
'}\\'' # { and } in comments, single quotes
\"}\\\"\" # or double quotes are…

Bugsgood
- 11
- 1
1
vote
3 answers
String interpolation with R's glue on a vector, without calling it multiple times
I'm looking to do string interpolation with R's glue::glue() on a vector, without calling it multiple times.
Example:
df <- data.frame(x = 1:10)
glue::glue("No. of Rows: {dim(df)[1]}, No. of Columns: {dim(df)[2]}")
Would give as required:
No. of…

Giora Simchoni
- 3,487
- 3
- 34
- 72
1
vote
2 answers
R glue with limited set of functions allowed in pattern?
I am using glue() to format strings. Ideally I would like to give the user the option to provide his own, potentially complex formatting patterns. These will usually be distributed as part of a yaml config file, which also contains many other…

meow
- 925
- 7
- 22
1
vote
0 answers
manipulating glue-generated title on my gganimate
I have created a basketball animation using gganimate, as seen below. You can get the full animation on my blog post (Look at animation under "Paul Pierce Isolation").
Now, there is one problem with this: once the seconds reach single digits, it…

Howard Baek
- 11
- 2
1
vote
1 answer
Glue and For to many models with Automl - R
I want to reproduce this code:
X_train_model1 <- data.table::fread("datasets_atualizados/dataset_y1.csv") %>%
h2o::as.h2o()
X_train_model2<- data.table::fread("datasets_atualizados/dataset_y2.csv") %>%
h2o::as.h2o()
#Model construction (20…

Guilherme Souza
- 13
- 3
1
vote
3 answers
Glue vector to string
I want to produce this string:
All my variables: a, b, c from this variable vars <- c("a", "b", "c") using glue().
My best attempt so far is:
library(glue)
glue('All my variables: {paste(vars, collapse = ", ")}')
Question:
Is there any easier /…

Tlatwork
- 1,445
- 12
- 35
1
vote
1 answer
Unable to upload latest glue package 1.3.0
I am doing a course in R and one of the codes they've asked us to run requires tidyr. I can install tidyr, but when I run the code I encounter: 'namespace 'glue' 1.2.0 is already loaded, but >=1.3.0 is required'. I have tried several ways to address…

Isobel M
- 55
- 1
- 6
1
vote
1 answer
R dplyr: rowwise + mutate (+glue) - how to get/refer row content?
The simple example of input data:
dataset <- data.frame("part1" = c("a", "b", "c"),
"part2" = c("x", "y", "z"),
"caption" = c("{part1} {part2}",
"{part2} {part1}",
…

RSzT
- 307
- 3
- 14
0
votes
0 answers
How to paste multiple values from an object to a string and have a single sentence output?
I need to paste the three values in tables to a string such as this: "The correct tables include:" and print it as a single sentence.
tables = c("Brif", "Amni","Calp")
Desired output:
The correct tables include: Brif, Amni, Calp
I use the…

Rara
- 105
- 9
0
votes
1 answer
How to add a condition to a generic case_when statement including the glue function?
I have two data frames (df1 and df2) as you can see in the tables below. Based on the conditions in df1, I need to check the values in df2. The expected output is also presented.
The condition is based on the columns dep and value in df1 checked in…

Rara
- 105
- 9
0
votes
0 answers
How to unzip file with different pattern name like alphanumeric folder name that changes everyday
I have plenty of zip files and I want to load only the ones that met the name condition
for example, unzip any file that has a name like this "Query Transaction History_20221122"
I was able to achieve that with the script below
zip_files…

Yomi.blaze93
- 401
- 3
- 10
0
votes
1 answer
How to retrieve a variable value inside a text string between quotes
I need to export a table from R to Excel.
One of the Excel columns has to be a hyperlink. So I'm adding a new column to build a string text using the "=HYPERLINK" function so Excel will interpret it as a hyperlink.
Excel HYPERLINK…

Leonardo Lira
- 15
- 5