Questions tagged [tidyselect]

Questions about `r` package `tidyselect` used in many functions from the `tidyverse` packages

88 questions
0
votes
0 answers

gt R package cells_summary row conditions issue

I'm trying to figure out how to get the select helpers to work in cell_summary. MRE: Consider the example below where we are trying to highlight certain cells based on its value. The code works for cells_body, but the same syntax fails for…
trian
  • 23
  • 2
0
votes
3 answers

Anonymous function in summarise() with pick(everything()) gives: error in pick() Can't subset columns past the end

I'm trying to understand how to use anonymous functions with summarise. For the sake of providing a simple MRE, if I do: tribble( ~A, ~N, "a", 1, "a", 2, "a", 3, "a", 4, "a", 5, "b", 1, "b", 2 ) %>% group_by(A)…
Ian
  • 1,507
  • 3
  • 21
  • 36
0
votes
1 answer

Unable to add primary keys to existing data model object

I'm not being able to add primary keys to an existing dm object using dm_add_pk. The error seems to appear only when the values are used dynamically (in a for loop for example) OR when its values are themselves captured on a separate variable. My…
oropo
  • 30
  • 6
0
votes
2 answers

select_if throwing error with second condition

df <- data.frame( id = rep(letters[1:3], 9), m1 = ceiling(rnorm(9, 10, 3)), m2 = ceiling(rnorm(9, 10, 6)), m3 = 0 ) head(df) id m1 m2 m3 1 a 12 14 0 2 b 11 9 0 3 c 10 10 0 4 a 16 1 0 5 b 5 15 0 6 c 8 7 0 I have a data…
Alex Romer
  • 27
  • 7
0
votes
1 answer

Select columns using starts_with()

With select(starts_with("A") I can select all the columns in a dataframe/tibble starting with "A". But how can I select all the columns in a dataframe/tibble starting with one of the letters in a vector? Example: columns_to_select <- c("A", "B",…
D. Studer
  • 1,711
  • 1
  • 16
  • 35
0
votes
1 answer

How to to avoid error message when an empty argument in dplyr::select function?

This is my code: empty <- "" mtcars %>% select(mpg,empty) Error in `select()`: ! Can't subset columns that don't exist. ✖ Column `` doesn't exist. The empty object is an output of a for loop. So if empty is equal "" I wouldn't need to select…
0
votes
1 answer

Calling/passing variables from a function to function

I'm trying to call some variable names using rlang and tidyselect from f1() to f2(). But it doesn't print. library(rlang) library(dplyr) library(R.utils) library(tidyselect) db <- tibble( D = as.factor(rbinom(10, size=1, p=0.7)), X1 =…
cdcarrion
  • 574
  • 6
  • 22
0
votes
2 answers

Using tidyselect in a function with mutate and

I have data like this: (test <- tribble( ~case, ~A.1_recipient, ~A.2_recipient, ~A.1_donor, ~A.2_donor, 1, "HLA-A2", "HLA-A3", "HLA-A2", "HLA-A68", 2, "A2", "HLA-A3", "A3", "A69", 3, "A11", "A24", "HLA-A2", NA, 4, "A66", NA, "A2", "A24" …
Nick Brown
  • 55
  • 6
0
votes
2 answers

How to pass tidyselect::starts_with(...) etc. to dplyr function(s)?

I would like to pass a column selection to a dplyr function (across) inside an ifelse statement. This is my data: tibble(var1 = c(NA,1,2), var2 = c(NA,NA,3), var3 = c(NA,0,0), do_not_touch = c(1:3) ) -> test This is what…
Dr. Fabian Habersack
  • 1,111
  • 12
  • 30
0
votes
1 answer

How to pass a character vector of negative tidyselect expression to select()

I'd like to exclude columns of a tibble. I got an exclude expression: a mix of possible column names and tidyselect expressions. This is what I tried: library(tidyverse) library(rlang) # my vector of columns and tidyselect…
piptoma
  • 754
  • 1
  • 8
  • 19
0
votes
2 answers

Tidyselect in custom function

I want to make a custom function that I can apply to a range of variables in a data frame using the var1:var20 tidyselect syntax, but I'm running into an error. A basic example below: library(dplyr) mtcars test_func <- function(start_var,end_var) { …
Jack Landry
  • 138
  • 8
0
votes
2 answers

R - Calculation on nested tibbles of the same size

I wish to calculate how each set of data in a tibble is different to a baseline dataset. to plan, I wrote this R code to subtract a tibble from another of the same size: # this works tbl_a <- tibble(a1 = 1, a2 = 2, a3 = 3) tbl_b <- tibble(a1 = 4, a2…
taiyodayo
  • 331
  • 4
  • 13
0
votes
0 answers

tidyverse: Using multiple columns in pmax function

I want to subtract maximum value of each row across multiple columns. For this I'm using pmax function which works if each column name is passed but I could not figured out how to use : for passing multiple columns. See my code…
MYaseen208
  • 22,666
  • 37
  • 165
  • 309
0
votes
1 answer

R - Using forcats fct_collapse in combination with tidyselect selection helpers

I have a messy factor variable, which contains various very similar factor levels (e.g. introduced by spelling mistakes, slightly different wordings etc.). I'm trying to combine the factor into four main categories using the fct_collapse function…
Rasul89
  • 588
  • 2
  • 5
  • 14
0
votes
2 answers

Rename columns of R dataframe with tidyselect and regular expression

I have a dataframe whose columns names are combinations of numbering and some complicated texts: A1. Good day A1a. Have a nice day ...... Z7d. Some other titles Now I want to keep only the "A1.", "A1a.", "Z7d.", removing both the preceding…
Miles N.
  • 165
  • 7