rstudio / gradethis

Tools for teachers to use with learnr
https://pkgs.rstudio.com/gradethis/
Other
161 stars 40 forks source link

Arguments are not standardized if passed through `...` from a map function to a function defined in setup code or user code #349

Closed rossellhayes closed 1 year ago

rossellhayes commented 1 year ago
library(gradethis)

# Arguments passed to package functions are standardized
with_exercise(
  mock_this_exercise(
    .user_code = "purrr::map(1:10, rnorm, 1)",
    .solution_code = "purrr::map(1:10, rnorm, mean = 1)"
  ),
  code_feedback()
)
#> NULL

# Arguments passed to functions defined in setup aren't
with_exercise(
  mock_this_exercise(
    .user_code = "purrr::map(1:10, foo, 1)",
    .solution_code = "purrr::map(1:10, foo, baz = 1)",
    setup_exercise = foo <- function(bar, baz) bar + baz
  ),
  code_feedback()
)
#> Your call to `purrr::map()` should include `"baz"` as one of its arguments. You may have misspelled an argument name, or left out an important argument.

# Arguments passed to functions defined in user code aren't
with_exercise(
  mock_this_exercise(
    .user_code = "
          foo <- function(bar, baz) bar + baz
          purrr::map(1:10, foo, 2)
        ",
    .solution_code = "
          foo <- function(bar, baz) bar + baz
          purrr::map(1:10, foo, baz = 2)
        "
  ),
  code_feedback()
)
#> Your call to `purrr::map()` should include `"baz"` as one of its arguments. You may have misspelled an argument name, or left out an important argument.

Created on 2023-05-15 with reprex v2.0.2