0

I was getting a dplyr::across error and I think to R's scipen option is impacting it. I am not sure why this would happen. I do not like seeing scientific notation, so I set this value high, but it seems like it breaks dplyr::across. Any thoughts on why would this happen and how to work around this?

library(tidyverse)
options(scipen=1e10)

# Using the example from https://dplyr.tidyverse.org/reference/across.html
gdf <-
  tibble(g = c(1, 1, 2, 3), v1 = 10:13, v2 = 20:23) %>%
  group_by(g)

set.seed(1)

# Outside: 1 normal variate
n <- rnorm(1)
gdf %>% mutate(across(v1:v2, ~ .x + n))

Error in local_error_context(dots = dots, .index = i, mask = mask) : 
  promise already under evaluation: recursive default argument reference or earlier problems?

Gives an error message, but works with lower values of scipen.

options(scipen=1000)
gdf %>% mutate(across(v1:v2, ~ .x + n))

# A tibble: 4 × 3
# Groups:   g [3]
      g    v1    v2
  <dbl> <dbl> <dbl>
1     1  9.37  19.4
2     1 10.4   20.4
3     2 11.4   21.4
4     3 12.4   22.4

1 Answers1

0

I think scipen=1e10 causes the error:

Try this: Using digits option. I am not sure if this is what you are looking for:And I think the syntax is like this:

library(tidyverse)
options(scipen=100, digits = 10)

# Using the example from https://dplyr.tidyverse.org/reference/across.html
gdf <-
  tibble(g = c(1, 1, 2, 3), v1 = 10:13, v2 = 20:23) %>%
  group_by(g)

set.seed(1)

# Outside: 1 normal variate
n <- rnorm(1)
gdf %>% mutate(across(v1:v2, ~ .x + n))

      g    v1    v2
  <dbl> <dbl> <dbl>
1     1  9.37  19.4
2     1 10.4   20.4
3     2 11.4   21.4
4     3 12.4   22.4
TarJae
  • 72,363
  • 6
  • 19
  • 66