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: warning type does not work properly as expected in data pipeline magrittr %>% #1010

Closed
Tracked by #1005
lizihao-anu opened this issue Sep 25, 2024 · 3 comments · Fixed by #1016
Closed
Tracked by #1005
Assignees
Labels
bug Something isn't working

Comments

@lizihao-anu
Copy link
Contributor

lizihao-anu commented Sep 25, 2024

Warning type fucntions include base::warning() and package cli, like cli::cli_alert_info().

@lizihao-anu lizihao-anu reopened this Sep 25, 2024
@lizihao-anu lizihao-anu changed the title Bug: sys.time() does not work properly as expected in data pipeline magrittr %>% Bug: warning type does not work properly as expected in data pipeline magrittr %>% Sep 25, 2024
@lizihao-anu
Copy link
Contributor Author

There are three examples to demonstrate how cli::cli_alert_info() works with magrittr %>%. It is also the same case with other warning type functions.

Code

Example 1 Example 2 Example 3
library(dplyr)
fn_a = function(data){
  data+2
  cli::cli_alert_info("A {Sys.time()}")
  Sys.sleep(1)
  return(data)
}

fn_b = function(data){
  data-1
  cli::cli_alert_info("B {Sys.time()}")
  Sys.sleep(5)
  return(data)
}

fn_c = function(data){
  data*2
  cli::cli_alert_info("C {Sys.time()}")
  Sys.sleep(5)
  return(data)
}

data = data.frame(
  x=1,
  y=1
)
data |>
  fn_a() |>
  fn_b() |>
  fn_c()

# Output
> data |>
+   fn_a() |>
+   fn_b() |>
+   fn_c()
ℹ A 2024-09-25 16:44:49B 2024-09-25 16:44:50C 2024-09-25 16:44:55
  x y
1 1 1
library(dplyr)
fn_a = function(data){
  cli::cli_alert_info("A {Sys.time()}")
  data = data+2
  Sys.sleep(5)
  return(data)
}

fn_b = function(data){
  cli::cli_alert_info("B {Sys.time()}")
  data = data-1
  Sys.sleep(5)
  return(data)
}

fn_c = function(data){
  cli::cli_alert_info("C {Sys.time()}")
  data = data*2
  Sys.sleep(5)
  return(data)
}

data = data.frame(
  x=1,
  y=1
)

data |>
  fn_a() |>
  fn_b() |>
  fn_c()

# Output
> data |>
+   fn_a() |>
+   fn_b() |>
+   fn_c()
ℹ C 2024-09-25 16:45:47B 2024-09-25 16:45:47A 2024-09-25 16:45:47
  x y
1 4 4
library(dplyr)
fn_a = function(data){
  1
  cli::cli_alert_info("A {Sys.time()}")
  Sys.sleep(1)
  return(data+2)
}

fn_b = function(data){
  1
  cli::cli_alert_info("B {Sys.time()}")
  Sys.sleep(5)
  return(data-1)
}

fn_c = function(data){
  1
  cli::cli_alert_info("C {Sys.time()}")
  Sys.sleep(5)
  return(data*2)
}

data = data.frame(
  x=1,
  y=1
)
data |>
  fn_a() |>
  fn_b() |>
  fn_c()

# Output
> data |>
+   fn_a() |>
+   fn_b() |>
+   fn_c()
ℹ C 2024-09-25 16:46:28B 2024-09-25 16:46:33A 2024-09-25 16:46:38
  x y
1 4 4

From the trials above, we may say if we want cli::cli_alert_info() to work as we expect, we need to "activate" the variable we want first.

@lizihao-anu lizihao-anu self-assigned this Sep 25, 2024
@lizihao-anu lizihao-anu added the bug Something isn't working label Sep 25, 2024
@lizihao-anu
Copy link
Contributor Author

Or, instead, we can put cli_alert_info() to the end before return.

@lizihao-anu
Copy link
Contributor Author

lizihao-anu commented Oct 15, 2024

close by #1016

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.

1 participant