The following code will filter a table of isotope combinations to identify combinations where only one element is isotopically enriched.
df <- tibble::tibble(
C12 = rep(c(2:0), 2),
C13 = rep(c(0:2), 2),
H1 = rep(c(0, 1), each = 3),
H2 = rep(c(1, 0), each = 3)
)
element_filter <- "H2"
dplyr::filter_at(df, dplyr::vars(element_filter), dplyr::all_vars(. == 0))
I would like to include this code in a package and avoid the no visible binding for global variable ‘.’ warning. When I change the filter_at call to
dplyr::filter_at(df, dplyr::vars(element_filter), dplyr::all_vars(.data == 0))
I receive the following error, Error: (list) object cannot be coerced to type 'double'. I am successfully using the .data pronoun in other functions, but am unable to figure out how to get it working here. Appreciate the help.
dplyr::filter_at(df, dplyr::vars(element_filter), dplyr::all_vars(. == 0))works for me without any warning.R version 3.5.2dplyr::filter_at(df, dplyr::vars(element_filter), dplyr::all_vars(.data == 0)), it doesn't. Why is that?all_varsdoesn't expect.dataargument??all_varssays it wants input asexpr. Though I maybe wrong here to interpret.filter. Are there cases where the table would have more than two different chemical elements? Also, do you only want cases where there is exactly one element that's isotopically enriched, or no more than one element that's isotopically enriched?expression_filteris determined based on a user-provided molecular formula that can also include N, O, S and their isotopes as well as an argument to indicate which element(s) are label-able.