Questions tagged [r-glue]

76 questions
10
votes
1 answer

Use of glue in map in an RMarkdown in a new environment

Consider the following Rmarkdown document: --- title: "Environments" author: "Me" date: "2023-01-13" output: html_document --- ```{r setup} library(glue) library(purrr) ``` ```{r vars} a <- 1 x <- list("`a` has the value: {a}") ``` ```{r…
thothal
  • 16,690
  • 3
  • 36
  • 71
8
votes
2 answers

Using `ggplotly` and `DT` from a `for` loop in Rmarkdown

Is that possible to use ggplotly() or datatable() in RMarkdown from inside a for loop or function? Example: --- title: "Using `ggplotly` and `DT` from a `for` loop in Rmarkdown" output: html_document --- ```{r setup,…
IVIM
  • 2,167
  • 1
  • 15
  • 41
6
votes
3 answers

Passing variables into the names_glue parameter of tidyr::pivot_wider

Here's some silly data that we pivot wider, using two names: library(tidyr) df <- data.frame( food = c('banana','banana','banana','banana','cheese','cheese','cheese','cheese'), binary = c(rep(c('yes','no'), 4)), car =…
heds1
  • 3,203
  • 2
  • 17
  • 32
4
votes
2 answers

Is there a way to suppress glue output in R, if the variable is empty?

I am creating a resume using pagedown. It takes a data.frame of CV inputs and generates a pagedown HTML output via glue package. However, if the variable is empty (as in the example below), glue generates a blank line. How can I prevent this…
4
votes
3 answers

Mutate using glue in a user defined function

I would like to change the values in a specific column to include information from another column using the glue function. I do it normally like this: library(glue) library(dplyr) df = data.frame(x = c("Banana","Apple","Melon"), y =…
Ran K
  • 162
  • 1
  • 5
4
votes
4 answers

Using dplyr::across with two sets of variables

I have two sets of variables, for example variable a and variable a_avail. I am trying to change the value of a based on the value of a_avail and am wondering if this can be done using across with glue. Here is what I have tried. No error is…
Jessica
  • 75
  • 5
4
votes
1 answer

Why does lazy evaluation "lose" a function argument?

I'm working with SQL and user input. So I'm using the glue library to handle with parameterized queries. However, to keep things clean, I wrapped that all in a function: safeQuery <- function(con, sql, ...) { sql = glue_sql(sql, ..., .con=con) …
Wasabi
  • 2,879
  • 3
  • 26
  • 48
3
votes
2 answers

Apply the glue function to all characted columns of with fields filled from the tibble

I need to allow the users of a function to add new columns with strings created from the values of the supplied tibble. A simple illustration: df <- data.frame(session=rep(LETTERS[1:3],2), bundle=rep(letters[1:2],3), …
Fredrik Karlsson
  • 485
  • 8
  • 21
3
votes
4 answers

Nesting glue function in custom function

I want to create a custom log function, that would get used in other functions. I am having issues with the custom function where arguments don't seem to flow through to the inner log function. My custom log function is inspired by the logger…
sactyr
  • 172
  • 1
  • 1
  • 14
3
votes
1 answer

Dynamic variables names in dplyr function across multiple columns

I am trying to write a function that uses dplyr::summarise to obtain means of multiple columns of a data frame and assign dynamic names to the summarised columns using the new rlang glue syntax and := operator. Here's a simple example of my problem…
Shellstar
  • 33
  • 2
3
votes
1 answer

pasting with glue::glue changes order of values in facet

Based on this response How to add greek letters to Facet_Grid strip labels? , I successfully create a ggplot with greek letters in the facet label. However the glue library changes the order of my label FacetX, how can I deal with it? This is an…
Sle R.
  • 87
  • 7
3
votes
2 answers

R SQL templating with glue_sql, ability to dynamically drop where clause

TLDR I would like to be able to template SQL queries and run them in R. The glue package and DBI work great, but I can't figure out a way to template statements. In other words, is there a way to do something like this (borrowing from jinja): SELECT…
Mark Druffel
  • 629
  • 4
  • 10
3
votes
2 answers

Partialised glue function does not work when called in different environment

I've partialised the glue function in a project I'm working on so that we can use agreed-on delimiters without having to tell glue about them all the time. But when we go to use the partialised function inside another function, it stops…
jimjamslam
  • 1,988
  • 1
  • 18
  • 32
3
votes
1 answer

How to use string manipulation functions inside .names argument in dplyr::across

Though I tried to search whether it is duplicate, but I cannot find similar question. (though a similar one is there, but that is somewhat different from my requirement) My question is that whether we can use string manipulation function such substr…
AnilGoyal
  • 25,297
  • 4
  • 27
  • 45
3
votes
2 answers

R use bang-bang within a glue statement

I'd like to make a simple function that takes a data frame and user supplied names for two columns in that data frame. The purpose would be to allow this to work easily with dplyr pipes. It will produce a character vector of glued strings: func <-…
Dylan Russell
  • 936
  • 1
  • 10
  • 29
1
2 3 4 5 6