Skip to main content
The 2024 Developer Survey results are live! See the results

Questions tagged [rlang]

rlang is an R package for creating tidy evaluation interfaces and manipulating language and environment objects. It is a utility package underlying many of the tidyverse family of packages.

0 votes
0 answers
46 views

What is the preferred / recommended rlang metaprogramming syntax to use on both sides of an assignment operator in the `dplyr::mutate()` function?

I have a question about an issue that's similar to this older question about the dplyr::filter() function, except that my example is a bit more complicated because dplyr::mutate() needs to process ...
stachyra's user avatar
  • 4,553
0 votes
1 answer
47 views

Is there a way to pass a string as a variable/column name to my function and use in a call to mutate?

I have a dataframe with a column indicating choices (of a survey) as well as a column indicating the index of the choice made in each row. e.g., df <- tibble( record_id = 1:9, choices = c(rep(&...
sometimes_sci's user avatar
0 votes
1 answer
32 views

How to make cli::cli_abort() evaluate dynamic arguments

How might I evaluate msg in this context? f <- function(msg){ cli::cli_abort("{msg} xxx") } f(msg = "{.var x}") # Error in `f()`: # ! {.var x} xxx # Run `rlang::last_trace()` ...
sparklink's user avatar
  • 131
0 votes
1 answer
31 views

Flextable background can't find column or recognize {{ }} or . within my function

I'm building a function that creates a table using flextable. I want to specify a color gradient, but some values are NA. I want those NA values--changed to be " - "--to be transparent. The ...
J.Sabree's user avatar
  • 2,442
2 votes
0 answers
57 views

Why does `dplyr::across()` substitute the symbol `.x` for the current column in a two-sided formula `.x ~ .x`, but not in a one-sided formula `~.x`?

I'm writing a function that takes a two sided formula with a purrr-style lambda expression on either side, e.g. f(.x) ~ g(.x) and converts those lambdas into two functions \(.x) f(.x) and \(.x) g(.x). ...
Ethan.S's user avatar
  • 41
1 vote
1 answer
50 views

What is the difference between expr and enexpr using tidy evalution in R?

In learning metaprogramming with R, I'm trying to understand the different concepts and mechanisms that form the tidy evaluation framework. I don't really understand the difference between expr() and ...
Ralph's user avatar
  • 194
3 votes
0 answers
43 views

converting function names to strings inside purrr::map [duplicate]

I'd like to convert a function into a string - further I'd like to use purrr::map() to turn many functions into strings. The motivating problem is to apply many functions to a data frame, and return a ...
jcken's user avatar
  • 485
3 votes
3 answers
115 views

Create function arguments from a character vector

Using the rlang package, I can create a function with the following expression: new_function(pairlist2(a = , b = ), quote(a * b)) Imagine that I have a & b in a character vector: arg_names <- ...
jandraor's user avatar
  • 349
0 votes
0 answers
35 views

Tidy/fable way to select many exogenous regressors from a data.frame?

Q: What is the tidy / tidyverts / fable way of selecting many exogenous regressors from a data.frame for use in model fitting, esp., with ARIMA()?  I set up a minimal working example below. You can ...
lowndrul's user avatar
  • 3,765
0 votes
0 answers
33 views

Specify exogenous regressors conditionally for each series in ARIMA?

Q: In the context of forecasting many series with exogenous regressors in the R tidyverts/fable framework, is there a tidy way to tell fable::ARIMA() that I want it to estimate, e.g., y~x1+x2 for ...
lowndrul's user avatar
  • 3,765
0 votes
1 answer
42 views

Run ARIMA without xreg when they're completely rank deficient?

Q: In the context of forecasting many series with exogenous regressors in the R tidyverts/fable framework, is there a way to tell fable::ARIMA(y~x1+x2+...) to fail over to running its routine for ...
lowndrul's user avatar
  • 3,765
1 vote
2 answers
50 views

Tidyeval and rlang within a nested tibble

I've attached a simple reproducible example below. I'm currently working within a nested tibble with dynamic column names. I'm using the purrr::map() function to pass the column data into an anonymous ...
Michael Luu's user avatar
2 votes
0 answers
66 views

An error occurs when uploading the tidyverse package to Google Colab: namespace ‘rlang’ 1.0.1 is already loaded, but >= 1.1.0 is required

When trying to use colab again after few days to write code in R, an error started to occur: Error: package or namespace load failed for ‘tidyverse’ in loadNamespace(i, c(lib.loc, .libPaths()), ...
Sofia Golovina's user avatar
2 votes
0 answers
95 views

How to update to latest version of ggplot in Google colab with R kernel?

It appears that within the past week (I write this on 4/20/2024), the default ggplot2 package version pre-installed with the R kernel in Google colab is 3.3.5, a very old version. I have lots of code ...
Silas Bergen's user avatar
2 votes
1 answer
79 views

Using rlang's arg_match for checking a list of function inputs

I am trying to quickly check a list of arguments for a function that each take a vector of strict values. I can do this one at a time: fn <- function(x = c("foo", "bar"), y = c(&...
dragon951's user avatar
  • 362

15 30 50 per page
1
2 3 4 5
55