Questions tagged [r-glue]
76 questions
3
votes
1 answer
Converting tidyeval arguments to string
I have a simple function in R with ... using tidyeval. Is is possible to change these into a string?
simple_paste <- function(...){
my_vars <- enquos(...)
paste(..., sep = "_x_")
}
simple_paste(hello, world)
As an output, I would like to get…

John-Henry
- 1,556
- 8
- 20
3
votes
1 answer
Cancel new line preventions in R's glue package
In the glue package you "can use \\ at the end of a line to prevent adding a newline". In LaTeX \\ is the new line symbol.
I am looking for a better solution than my current one
glue_data(iris,
"\\midrule
\\textbf{{{mean(Petal.Length)}} & 820 & …

s_baldur
- 29,441
- 4
- 36
- 69
2
votes
1 answer
Adding decimal places for glue command in ggplot
Continuation to this question.
The labels in facet_wrap() contains numbers with different decimal places. I used glue R package. The codes and the associated figures are given below.
data <- data.frame(N = runif(30, 200, 600),
…

RRMT
- 137
- 5
2
votes
3 answers
Extract top positive and negative values from dataframe and fill them into a formatted text using R
I'm trying to extract material infos whose price increase and decrease the most top 3 base on pct_change column.
Data:
df <- structure(list(material = c("Copper", "Aluminum", "Iron", "Zinc",
"Nickel", "Silver", "Gold", "Tin"), price = c(17125,…

ah bon
- 9,293
- 12
- 65
- 148
2
votes
2 answers
Way to use glue_sql() and avoid paste in dynamic SELECT statement?
I'm learning how to query SQLite dbs from R, and building those queries with glue_sql(). Below is a simplified example of a sub-query from my workflow. Is there a way I can create s10_wtX and s20_wtX without using paste0(), as in the code…

CzechInk
- 443
- 2
- 13
2
votes
2 answers
glue and rlang: how to tunnel data-variables within a glue string?
As per this article, a recent version of rlang and glue allows to combine tunnelling {{ myobj }} into a glue string:
library(dplyr)
library(rlang)
library(glue)
mean_by <- function(data, by, var, prefix = "avg") {
data %>%
group_by({{ by }})…

Phil
- 7,287
- 3
- 36
- 66
2
votes
2 answers
Create glue string with mixture of single and double quotes
I am trying to create a string using the glue package in R
which is a mixture of 'single' and "double" quotes.
As a reprex, consider the following type of SQL query
string I want to build:
CREATE TABLE fact_final_table AS
(SELECT tab1.id,
…

user4687531
- 1,021
- 15
- 30
2
votes
1 answer
r - use `glue` to substitute variables in a column with whats in another column
I am trying to keep a data frame were I have a list of messages for the user. I'd like to be able to substitute my variables in my message with what is in the column i am referencing.
For example, this works:
df <- data.frame(id = rep(1:3, each =…

alexb523
- 718
- 2
- 9
- 26
2
votes
1 answer
How can I make a collapse with glue package using RMarkdown?
I've been trying to automate the results of some df table in latex using the glue and stargazer packages, but I haven't had any results (what I want is for the meaning "^{*}" to appear next to each value as it is in the table) to use then…

cdcarrion
- 574
- 6
- 22
2
votes
2 answers
Get level names using glue and dplyr in a loop
I am trying to get level names from a table using dplyr and glue in a loop (I use a loop because I get a large number of variable to get grouped tables and individual tables), I show an example below:
library(dplyr)
library(glue)
var=c( "vs",…

Rodrigo
- 121
- 8
2
votes
0 answers
magrittr placeholder gets duplicated in glue string
I'd like to build a character value with the month name in it. I can extract the month name by using today() >%> months(), but as soon as I pipe the result into glue(), and start using the placeholder (.), the value behind the placeholder gets…

piptoma
- 754
- 1
- 8
- 19
1
vote
2 answers
Preserving indentation with glue
When using the R package glue, the following code
glue("foo\n bar")
results in
foo
bar
However, I would prefer it to produce
foo
bar
I could do the following
. <- " "
glue("foo\n{.}bar")
but it is ugly. Interestingly, the following works as…

January
- 16,320
- 6
- 52
- 74
1
vote
1 answer
After_stat() and glue() do not work together
I would like to create a plot using plotly::ggplotly(). This works just fine.
library(ggplot2)
#> Warning: package 'ggplot2' was built under R version 4.2.2
p <-
mtcars |>
ggplot() +
geom_histogram(
aes(
x = disp,
text =…

joshbrows
- 77
- 7
1
vote
2 answers
Use substrings of column names in across
I have the following tibble:
df <- tibble(
x = c(5, 5),
Column_1 = c(0.5, 0.5),
Column_2 = c(0.75, 0.75))
I would like to create two new columns, which are the product of column x and Column_1 and x and Column_2 respectively. These columns…

snowman
- 33
- 3
1
vote
1 answer
How to add the list in glue_sql to Where filter
I’m writing a function and I wanted to paste a list typed by user to filters in WHERE.
List typed to function by user:
filters = list( ‘fruits’ = c(‘apple’,’orange’),
‘vegetables’ = ‘carrot’)
How to paste this list to sql query in glue sql:
df =…

werrk a
- 13
- 2