491 questions
2
votes
1
answer
115
views
Programmatically filter using expressions stored in another data frame
I have a data frame containing the specification for a set of regression models (regress_grid) with a column for different aspects of the model. I then use dplyr::rowwise() to estimate a model for ...
4
votes
1
answer
102
views
force order of evaluation inside a tidypolars call
Is it possible in some way to force the evaluation order in a {tidypolars} pipe?
For example:
install.packages("tidypolars", repos = c("https://community.r-multiverse.org", '...
4
votes
3
answers
184
views
extracting grouping variables for fgroup_by using collapse package
I want to create a custom function for the collapse package where I supply unquoted grouping variables like so:
library(collapse)
library(tidyverse)
fgroup_by_no_entries <- function(df, ...) {
...
1
vote
1
answer
58
views
Wrapper around deparse() and substitute()
I'm trying to write a function that would simply wrap around deparse() and substitute() like so:
get_name <- function(x) {
deparse(substitute(x))
}
The point of get_name() is to return the ...
0
votes
1
answer
60
views
Passing a function to `across()` inside `mutate()`
Here is what I want to achieve
library(dplyr)
mtcars %>% dplyr::summarise(
dplyr::across(mpg, ~ sum(.x) / sum(vs))
)
#> mpg
#> 1 45.92143
if I have this function stored in an object, I ...
0
votes
1
answer
58
views
Running R Script at command line with commandArgs value in tidy evaluation in R programming
I have a r script, named myrsciprt.R as follows:
library(ggplot2)
library(ggpubr)
library(palmerpenguins)
create_plots_pdf <- function(output_filename, group_name){
# Histogram example: ...
1
vote
1
answer
40
views
Is it possible to create a ggplot with interactions with tidy evaluation
I am trying to create a plot function that can plot different colors for a column with factors if .f2=NULL, and an interaction of the .f1 and .f2 columns if the .f2 parameter is not NULL.
The if ...
2
votes
1
answer
144
views
How to write a function with tidy eval when using the "arrow" R package (arrow::open_dataset) and dplyr verbs?
What I'm trying to do
I'm attempting to write a function that uses dplyr verbs and that takes an "arrow open dataset" as the first argument, and a column in that dataset as the second ...
2
votes
1
answer
93
views
How to include a lookup table in a function for R ggplot graph and/or pass certain strings into graph?
I am trying to write a function in R for re-creating a ggplot graph. The graph is using climate data, and I want to be easily able to remake it for 3 different climate scenarios (rcp column) and ...
0
votes
1
answer
36
views
How to flexibly supply a varying length argument to .l of pmap()
Below is a pmap() operation that requires my data to be in wide format. I perform a few simulations each day and capture the max value per simulation as post_max.
library(tidyverse)
POST_SIMS <- 2
...
0
votes
1
answer
68
views
Tidy eval failing within a function
I'm trying to automate the production of .tex tables and I want to add in the add.lines section of stargazer a value called mean_outcome but I'm having trouble producing this value, I think I'm ...
2
votes
2
answers
2k
views
Tidyeval problem in `case_when` when using function in right side formula
Consider the following structure:
tmp_data <- structure(
list(
currency = c("EUR", "USD"),
funding = c(50, 700)),
class = c("tbl_df", "tbl", "...
2
votes
1
answer
149
views
Build a dynamic-dots list to read dataframe one row at a time
I am trying to build a GET request one row at a time from a dataframe where the possible parameters are a varied and large list, and the dataframe I'm passing to the function may not have the ...
1
vote
1
answer
87
views
Why are these error messages inconsistent when using NSE in R?
Question
Why do I get inconsistent error messages in R from a function that uses non-standard evaluation, and what is the best way to control this / write the function?
Initial setup that works as ...
0
votes
2
answers
473
views
How to use external character values to select x and y variables in ggplot?
I have data with multiple observable variables (say, x,y,z), indexed by another set of variables (sect, and item). Each time I run an experiment I get such a set of observations. So for experiment &...
0
votes
0
answers
35
views
Unsure what is wrong with summarize() in my custom function
I have a list of tables that I need to make using different variables, and I want to make a function that will let me make the tables differently each time by passing through different variables as ...
2
votes
1
answer
93
views
Write function that access data from dplyr context
Disclaimer: this is a very elemental question. I'll use an example to make it easier, but the question has nothing to do with the example itself.
Supose you have a dataframe df:
# A tibble: 5 × 4
...
0
votes
2
answers
313
views
how to avoid tidy evaluation (especially double curly brace) in user define function in r?
id <- 1:30
x<-rnorm(30,1,10)
y<-rnorm(30,1,10)
data<-data.frame(id,x,y)
add<-function(data,
y_1,
y_2){
data<-dplyr::mutate(data,
...
2
votes
2
answers
145
views
Use custom function (with tidy eval) within mutate & across
I have the following data:
my_data <- structure(list(case_one = c("A", "B", "A", "B", "A", "B", "A",
"B", "A&...
1
vote
1
answer
93
views
using dot-dot-dot (`...`) with `str_replace_all()` in R
I have a function which is a wrapper around stringr::str_c(), and therefore receives any number of character vectors as input using the ... argument.
The issue is that I would like to perform some ...
1
vote
1
answer
121
views
pass values through to piped dplyr verb inside if{} statement in function
Say I have this data:
d <- msleep %>%
mutate(comfort_color_desk = sample(c(0,1), replace=TRUE, size=nrow(msleep)),
comfort_color_chair = sample(c(0,1), replace=TRUE, size=...
1
vote
1
answer
67
views
Can you use a parameter in a function name with tidy eval/NSE/metaprogramming?
I am writing a function that makes ggplots with given data, and I am interested in setting a parameter that can call the different scales::label_* functions to change the outputs. For example, I want ...
0
votes
1
answer
85
views
Tidy eval for `by` in `dplyr::_join
I am writing a function to join two datasets using dplyr::_join where the by terms are parameters passed in without quotes. I have seen quite a few solutions to this issue, but all seem to be dated ...
1
vote
3
answers
244
views
R - dplyr how do I reference a column created in a function with the walrus operator :=
I am trying to create a function and I want to reference a column I previously created inside the function with the {{}} and :=. How can I reference the "{{col}}_d" column?
library(...
1
vote
1
answer
424
views
Use mutate + across with case_when with a list of conditions
I want to modify a list of columns. Each column has a list of conditions that need to be applied with a case_when.
I tried the following:
df <- tibble(value=c("a","b","c&...