Questions tagged [tidyselect]

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

88 questions
1
vote
2 answers

`dplyr::select()` with tidyselection but not error if column doesn't exist

I have a function that applies to a dataframe, with the exception of some columns. These columns can be filled using tidyselection. For example, consider this function: rename_upper = function(df, except=NULL){ except = names(select(df,…
Dan Chaltiel
  • 7,811
  • 5
  • 47
  • 92
1
vote
2 answers

How to scale up a transmute in tidyverse?

I have a tibble with many variables organised this way: tibble( A = rep("A",10), xyz1 = rnorm(10), xyz2 = rnorm(10), xyz3 = rnorm(10), abc1 = rnorm(10), abc2 = rnorm(10), abb3 = rnorm(10), acc4 = rnorm(10) ) where xyz, abc, etc. are…
GiulioGCantone
  • 195
  • 1
  • 10
1
vote
3 answers

Using everything() from tidyselect in dplyr to select a variable last

I would like to programmatically tell what column I'd like to display LAST. The function everything() from tidyr is great when it is used as the last argument --you specify everything before it and let it do the rest But what if I want to do it the…
RayVelcoro
  • 524
  • 6
  • 21
1
vote
4 answers

Calculate the rowwise mean when a maximum number of NA values is given for a set of columns using dplyr

Example dataset... > tribble( + ~colA, ~colB, ~colC, ~colD, ~colE, + 1, 2, 3, 4, 5, + 2, 3, NA, 4, 5, + 3, NA, NA, NA, 4, + 4, NA, NA, 5, 6 + ) # A tibble: 4 × 5 colA colB colC colD colE 1 1 2…
Tom
  • 279
  • 1
  • 12
1
vote
1 answer

Using start_with function along with collapse::fselect funcation

The starts_with("O") from tidyselect works well with dplyr::select function but not with collapse::fselect. Wondering if I'm missing some basic here. library(collapse) library(tidyverse) wlddev %>% select(starts_with("O")) %>% head() #> …
MYaseen208
  • 22,666
  • 37
  • 165
  • 309
1
vote
1 answer

i want to write a custom function with tidyverse verbs/syntax that accepts the grouping parameters of my function as string

I want to write a function that has as parameters a data set, a variable to be grouped, and another parameter to be filtered. I want to write the function in such a way that I can afterwards apply map() to it and pass the variables to be grouped in…
mcmurphy
  • 104
  • 6
1
vote
1 answer

How to write a function with ... (dot-dot-dot) that can also accept tidyselect helpers?

I want to write a custom function that wrangles data. The function's input should be: data.frame object names of columns in the data that are relevant to what the function is going to do. I want to program this function such that the argument…
Emman
  • 3,695
  • 2
  • 20
  • 44
1
vote
2 answers

Drop column range starting with first column matching regex

I have the following dataframe, which is the output of read_excel with missing column names in excel: t <- tibble(A=rnorm(3), B=rnorm(3), "x"=rnorm(3), "y"=rnorm(3), Z=rnorm(3)) colnames(t)[3:4] <- c("..3", "..4") How can I select columns ..3 to Z…
c0bra
  • 1,031
  • 5
  • 22
1
vote
1 answer

How to splice a tidyselect-style list of column names into a call of my function

I am trying to write a function that deduplicates my grouped data frame. It asserts that the values in each groups are all the same and then only keeps the first line of the group. I am trying to give it tidyselect-like semantics like are seen in…
akraf
  • 2,965
  • 20
  • 44
1
vote
1 answer

Adding tidyselect helper functions to a vector

I often create a "vector" of the variables I use most often while I'm coding. Usually if I just input the vector object in select it works perfectly. Is there any way I can use in the helper functions in a string? For example I could…
John-Henry
  • 1,556
  • 8
  • 20
1
vote
2 answers

renaming column names with dplyr using tidyselect functions

I am trying to rename a few columns using dplyr::rename and tidyselect helpers to do so using some patterns. How can I get this to work? library(tidyverse) # tidy output from broom (using development version) (df <-…
Indrajeet Patil
  • 4,673
  • 2
  • 20
  • 51
1
vote
1 answer

selecting specific columns using `tidyselect` in `dplyr::filter_at`

This works as expected except for the fact that the column meaningful is also selected. I just want the following columns to be selected: mean...summary, mean.conf.low...summary, mean.conf.high...summary How can I do that? library(tidyverse) #…
Indrajeet Patil
  • 4,673
  • 2
  • 20
  • 51
1
vote
1 answer

How to copy attributes from one data frame to another or to re-assign attributes to a freshly transposed data frame - R

After transposing data I'd like to re-assign attributes that are dropped. This could also be applicable to copying attributes from one data frame to another. Or copying attributes after mutates, etc., where they are dropped. library(reshape2) df…
23stacks1254
  • 369
  • 1
  • 9
1
vote
1 answer

Error: could not find function "lang_unnamespace"

I am getting the error here in this Travis build, and I cannot reproduce it locally. Yes, I realize that I do not have a minimal reproducible example, but I do know that it happens within tidyselect::vars_select(). Has anyone else encountered this…
landau
  • 5,636
  • 1
  • 22
  • 50
0
votes
1 answer

R gt table - Exclude NA values from text transform

how can I exclude NA values from being transformed into an icon? With the code below you require to have NA-Icons aswell, which I just colored like the backround to disappear. Is there a better way to just exclude NA to be required to transform? All…
Essi
  • 761
  • 3
  • 12
  • 22