Questions tagged [quasiquotes]

70 questions
1
vote
2 answers

how quasiquotes are represented in syntax tree (CL)

I understand how quotes are represented in language: (equal ''(1 2) (list 'quote (list 1 2))) ;; => T but what about quasi-quotes? is it something like: (equal ``(1 2) (list ' (list 1 2))) Both quasiquote and backquote instead of don't…
aaalex88
  • 619
  • 4
  • 13
1
vote
1 answer

Changing legend order in ggplot within a function

I want to plot a data frame within a function. The legend should be ordered in a specific way. To keep things simple in my example I just reverse the order. I actually want to select a specific row and push it to the last position of the legend. By…
1
vote
1 answer

Mixed input in quasiquotation with dplyr

I've taken quasiquotation to a top level. I'm close to getting my master-quasiquotator badge (see edits below). There's one chellenge bit left. Using different inputs to create quosures with dplyr. The end result is: the_quote <- quo(…
Diego-MX
  • 2,279
  • 2
  • 20
  • 35
1
vote
1 answer

Pass multiple calling arguments to a formal argument in dplyr custom function without using "..."

To make a custom function flexible to receiving one or more calling arguments per formal argument I currently rely on "...": library(dplyr) foo <- function(data, ..., dv){ groups <- enquos(...) dv <- enquo(dv) data %>% …
Joe
  • 3,217
  • 3
  • 21
  • 37
1
vote
1 answer

Passing variables to functions that use `enquo()`

I have a conceptual problem. I want to pass variables to a function that turns some of these variables into quosures via enquo (from the dplyr/rlang packages). However, I want to do so via other functions. Consider the following, which has a…
Zeke
  • 617
  • 1
  • 6
  • 15
1
vote
1 answer

Why can't I unquote this quosure?

I'm reading through some notes on quasiquotation here: https://dplyr.tidyverse.org/articles/programming.html. After my first read, I've tried a few things out. One in particular has me confused: x <- "foo" q <- quo(x) print(x) expr:…
Al R.
  • 2,430
  • 4
  • 28
  • 40
0
votes
2 answers

R: Select the first non-NA data for each row, within an arbitrarily long subset of variables

I'm trying to write a function in R; let's call it favor(). It needs to accept an arbitrary number of columns of a tibble, which may not contain complete data. For each row in the dataset, favor() will examine the contents of each column provided…
seaweedbrain
  • 303
  • 2
  • 4
0
votes
1 answer

Issue adapting a function that takes as argument a column name

I have the following function that has two actions: 1) takes a column character and converts all characters to lowercase, 2) removes any special characters that may be present in the column. clean_string<-function(data,variable){ data <- data |>…
Francisco
  • 119
  • 6
0
votes
1 answer

How to mutate across multiple columns and paste the relevant column name as the cell entry?

I'm trying to mutate across multiple columns to paste in the column name as the entry where the entries are/are not NA. Using airquality dataset > head(airquality) Ozone Solar.R Wind Temp Month Day 1 41 190 7.4 67 5 1 2 36 …
lilblue
  • 84
  • 7
0
votes
1 answer

How to runtime compile with reflection for a class being used within another class

My code: import scala.reflect.runtime import scala.reflect.runtime.universe import scala.reflect.runtime.universe._ import scala.tools.reflect.ToolBox object Stuff { val rm: universe.Mirror = runtime.currentMirror val tb: ToolBox[universe.type]…
0
votes
1 answer

Trying to purrr:::map a function across a vector, getting `non-numeric argument` error

I want to map a function to generate summary statistics across a defined vector of columns. When I run the function alone it works fine, but when I map it I'm getting a non-numeric argument to mathematical function error. Here's the…
daaronr
  • 507
  • 1
  • 4
  • 12
0
votes
1 answer

Why is `(,x) a shorthand for (cons x '())?

I'm told that: `(,x) is a shorthand for (cons x '()). I'm a bit confused because that's not documented anywhere. Also if that is the case, what does `(((pea)) ,q) evaluate to? And why is pea wrapped in two sets of parens?
Alper
  • 3,424
  • 4
  • 39
  • 45
0
votes
1 answer

generalise a mutate to all columns of a tibble

I would like to generalise this line of code to all the columns of the tibble: starwars_with_species_as_last_column <- starwars %>% select(1:11) # not interested in generalising this starwars_with_species_as_last_column %>% transmute(text =…
Dario Lacan
  • 1,099
  • 1
  • 11
  • 25
0
votes
1 answer

R7RS-small: equivalence of quasiquoted expressions

The R7RS-small standard, section 4.2.8 Quasiquotation on page 20-21 says that (let ((a 3)) `((1 2) ,a ,4 ,'five 6)) is equivalent to `((1 2) 3 4 five 6) and (let ((a 3)) (cons '(1 2) (cons a (cons 4 (cons 'five '(6)))))) But not…
Flux
  • 9,805
  • 5
  • 46
  • 92
0
votes
1 answer

Passing enquo expression to subfunction

This question is related to Passing variables to functions that use `enquo()`. I have a higher function with arguments of a tibble (dat) and the columns of interest in dat (variables_of_interest_in_dat). Within that function, there is a call to…
IrisOren
  • 69
  • 1
  • 1
  • 6