Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in across.() when used in map.() #505

Closed
psychelzh opened this issue Jun 19, 2022 · 3 comments · Fixed by #508
Closed

Bug in across.() when used in map.() #505

psychelzh opened this issue Jun 19, 2022 · 3 comments · Fixed by #508
Labels
bug Something isn't working

Comments

@psychelzh
Copy link

psychelzh commented Jun 19, 2022

See the difference between {tidytable} and {tidyverse}. Seemingly the expression is quoted and not evaluated when used in map.().

  • tidytable:
tibble::tribble(
  ~id, ~data,
  1, data.frame(x = runif(5))
) |> 
  tidytable::mutate.(
    data = tidytable::map.(
      data,
      ~ . |> 
        tidytable::mutate.(
          tidytable::across.(
            .fns = as.character
          )
        )
    )
  ) |> 
  purrr::pluck("data", 1)
#> # A tidytable: 5 × 2
#>       x `vctrs::data_frame(id = as.character(id), data = as.character(data))`
#>   <dbl> <list>                                                               
#> 1 0.537 <df [1 × 2]>                                                         
#> 2 0.648 <df [1 × 2]>                                                         
#> 3 0.181 <df [1 × 2]>                                                         
#> 4 0.518 <df [1 × 2]>                                                         
#> 5 0.705 <df [1 × 2]>
  • tidyverse
tibble::tribble(
  ~id, ~data,
  1, data.frame(x = runif(5))
) |> 
  dplyr::mutate(
    data = purrr::map(
      data,
      ~ . |> 
        dplyr::mutate(
          dplyr::across(
            .fns = as.character
          )
        )
    )
  ) |> 
  purrr::pluck("data", 1)
#>                   x
#> 1 0.733133836183697
#> 2 0.584197593852878
#> 3 0.689167245756835
#> 4 0.466306854970753
#> 5  0.54416445363313

Created on 2022-06-19 by the reprex package (v2.0.1)

@psychelzh
Copy link
Author

psychelzh commented Jun 19, 2022

Seemingly, this is because of the formula function error. Normal function works as expected.

tibble::tribble(
  ~id, ~data,
  1, data.frame(x = runif(5))
) |> 
  tidytable::mutate.(
    data = tidytable::map.(
      data,
      \(x) {
        tidytable::mutate.(
          x,
          tidytable::across.(
            .fns = as.character
          )
        )
      }
    )
  ) |> 
  purrr::pluck("data", 1)
#> # A tidytable: 5 × 1
#>   x                
#>   <chr>            
#> 1 0.267508938442916
#> 2 0.441175762796775
#> 3 0.356469556922093
#> 4 0.83364535542205 
#> 5 0.774993801722303

Created on 2022-06-19 by the reprex package (v2.0.1)

@markfairbanks markfairbanks added the bug Something isn't working label Jun 19, 2022
@markfairbanks
Copy link
Owner

Thanks for catching this - I'll take a look and see what I can figure out.

@markfairbanks
Copy link
Owner

All set.

set.seed(123)
library(tidytable, warn.conflicts = FALSE)

df <- tidytable(id = 1, data = list(data.frame(x = round(runif(5), 4))))
                
df %>%
  mutate.(
    data = data %>%
      map.(
        ~ . |> 
          mutate.(
            across.(.fns = as.character)
          )
    )
  ) %>%
  purrr::pluck("data", 1)
#> # A tidytable: 5 × 1
#>   x     
#>   <chr> 
#> 1 0.2876
#> 2 0.7883
#> 3 0.409 
#> 4 0.883 
#> 5 0.9405

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants