Skip to content

Document how index arg works for nested functions #214

@richierocks

Description

@richierocks

Consider this ggplot

library(ggplot2)
ggplot(Orange, aes(age, circumference)) +
  geom_point() +
  geom_line(aes(color = Tree))

This has 2 calls to aes(), so on first glance, it seems I want to check this with

ex() %>% check_function("ggplot") %>% {
  check_arg(., "data") %>% check_equal()
  check_arg(., "mapping") %>% check_function("aes") %>% {
    check_arg(., "x") %>% check_equal(eval = FALSE)
    check_arg(., "y") %>% check_equal(eval = FALSE)
  }
}
ex() %>% check_function("geom_point") %>% {
  check_arg(., "mapping") %>% check_function("aes", index = 2) %>% {
    check_arg(., "color") %>% check_equal(eval = FALSE)
  }
}

But the each call to aes() is nested inside another check_function(), and I think this is restricting the scope. So I think the SCTs I really need are

ex() %>% check_function("ggplot") %>% {
  check_arg(., "data") %>% check_equal()
  check_arg(., "mapping") %>% check_function("aes") %>% {
    check_arg(., "x") %>% check_equal(eval = FALSE)
    check_arg(., "y") %>% check_equal(eval = FALSE)
  }
}
ex() %>% check_function("geom_point") %>% {
  check_arg(., "mapping") %>% check_function("aes") %>% {  # <- this line different
    check_arg(., "color") %>% check_equal(eval = FALSE)
  }
}

It's worth having an example of how the index is calculated: on the whole code or on a subset of the code provided by the state.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions