Questions tagged [quasiquotes]

70 questions
3
votes
2 answers

Named vector "by" arguments for `dplyr::_join` functions

I am writing a function to dplyr::_join two dataframes by different columns, with the column name of the first dataframe dynamically specified as a function argument. I believe I need to use rlang quasiquotation/metaprogramming but haven't been able…
maia-sh
  • 537
  • 4
  • 14
3
votes
1 answer

Only strings can be converted to symbols within a function in R

I have a function that is intended to operate on data obtained from a variety of sources with many manual entry fields. Since I don't know what to expect for the layout or naming convention used in these files, I want it to 'scan' a data frame for…
SGE
  • 311
  • 3
  • 10
3
votes
3 answers

Why is plotly() and enquo + !! in conflict?

I am writing a function that uses plot_ly for a pieplot. The tilde (~) within argument labels = ~ is in conflict with the unquote operator !!. Is there a solution for this problem? pieplotr <- function (df, Property){ Property_Name <-…
Soph Carr
  • 31
  • 5
3
votes
1 answer

Haskell analog of lisp backquoting and splicing

In some lisps (e.g. elisp, common lisp) there is a feature called backquoting. It allows to construct a list while evaluating or splicing into it some elements. For example: `(1 2 (3 (+ 4 5))) ⇒ (1 2 (3 (+ 4 5))) ; just quoted unevaluated…
grepcake
  • 3,960
  • 3
  • 16
  • 26
3
votes
1 answer

How can I write a pattern quasi quoter in Haskell?

I use quasi quoters to create my smart-constructed data types at compile time. This looks something like: import qualified Data.Text as T import Language.Haskell.TH.Quote (QuasiQuoter(..)) import Language.Haskell.TH (Q, Exp, Pat(..), Lit(..)) import…
MaxGabriel
  • 7,617
  • 4
  • 35
  • 82
3
votes
1 answer

Using a quasiquoted argument to a function within a purrr:map call

I'm having a little trouble figuring out quasiquotation, specifically I have a function which takes an argument which specifies which variable should go into a model which is then run within a purrr::map call. I've been working from:…
Richard J. Acton
  • 885
  • 4
  • 17
3
votes
2 answers

Using rlang::sym inside list definition

I'm writing an R script and I need to allow user to specify the name of variable that will be proccessed by hand, i.e. var <- 'user_name' Generally then I refer to that using rlang::sym and quoting/unquoting mechanism. However, I need to use…
jakes
  • 1,964
  • 3
  • 18
  • 50
3
votes
2 answers

Haskell QuasiQuotes Text.RawString.QQ interpolation

How can I interpolate like this: {-# LANGUAGE QuasiQuotes #-} import Text.RawString.QQ myText :: Text -> Text myText myVariable = [r|line one line two line tree ${ myVariable } line five|] myText' :: Text myText' = myText "line four" ${…
FtheBuilder
  • 1,410
  • 12
  • 19
3
votes
0 answers

Non linear patterns in quasi-quotes

I followed this tutorial to implement a quasi quoted DSL, and I now want to support non-linear patterns in a quoted pattern. That will allow a repeated binder in a pattern to assert the equality of the matched data. For example, one can then write…
rem
  • 893
  • 4
  • 18
2
votes
1 answer

How to pass more than one environmental variable name to `by` parameter in dplyr `join` functions?

Let's say I'm writing a wrapper function for full_join (but the question applies to left_join, right_join, and inner_join). The join variables need to be specified by the user in the function call and the function needs to allow for situations when…
ESELIA
  • 132
  • 1
  • 12
2
votes
1 answer

Is it legal to modify a list created using quasiquote?

From my understanding, it is not legal to modify a list created using quote: (let ((numbers '(3 2 1))) (set-car! numbers 99) ; Illegal. numbers) What about lists created using quasiquote? Is it legal to modify lists created using…
Flux
  • 9,805
  • 5
  • 46
  • 92
2
votes
2 answers

default arguments not being recognized in custom function using dplyr

Take this function foo(). I want it to have a default argument of cyl because that's the name of the field it will usually process. library(tidyverse) foo <- function(x = cyl){ case_when( x == 6 ~ TRUE, x == 8 ~ FALSE, x…
Joe
  • 3,217
  • 3
  • 21
  • 37
2
votes
1 answer

Unquoting argument inside of function in R

I cannot figure out why the bang-bang operator in my function is not unquoting my grp argument. Any help would be much appreciated! library(dplyr) test_func <- function(dat, grp){ dat %>% group_by(!!grp) %>% summarise(N = …
Jordan Hackett
  • 689
  • 3
  • 11
2
votes
2 answers

Pass string as argument to paste function

I'm trying to pass string variable names to the paste function to paste all strings together. Here's a mwe: #bind strings to variable names a <- c("abc", "def", "ghi") b <- c("jkl", "mno", "pqr") c <- c("stu", "vwx",…
Tea Tree
  • 882
  • 11
  • 26
2
votes
2 answers

Using `expr()` inside the function

The Chapter 19 of Advanced R explains that expr() is not useful inside the function. However, in the following case, I could not make a function work without expr(). Let's suppose I want to group a tibble in a function. data(iris) iris %>%…
user51966
  • 967
  • 3
  • 9
  • 21