Compatibility between theme_sub_* functions and RStudio’s "Check arguments to R function calls" option
Closed this issue · 5 comments
Thanks for the report!
To reproduce, create a new file with the following content. Make sure it is saved.
library(ggplot2)
theme_sub_axis_x(
title = element_blank()
)Check the 'Check arguments to R function calls' option. A yellow note will appear at the line number and upon hover shows the diagnostics.
The thing I don't understand here is why this happens with theme_sub_*(), but not with theme(). Does RStudio make an exception somewhere for a list of selected functions?
I checked the contents of the theme() function and the theme_sub_*() functions.
The formal arguments of the theme() function include three dots. As is often the case, I think they are used either to pass along unused variables or to forward arguments to the parent object, but this might be the cause.
theme_sub_axis_y()
function (title, text, ticks, ticks.length, line, minor.ticks.length)
{
subtheme(find_args(), "axis.", ".y")
}theme()
function (..., line, rect, text, title, point, polygon, geom,
spacing, margins, aspect.ratio, axis.title, axis.title.x,
axis.title.x.top, axis.title.x.bottom, axis.title.y, axis.title.y.left,
axis.title.y.right, axis.text, axis.text.x, axis.text.x.top,
axis.text.x.bottom, axis.text.y, axis.text.y.left, axis.text.y.right,
axis.text.theta, axis.text.r, axis.ticks, axis.ticks.x,
axis.ticks.x.top, axis.ticks.x.bottom, axis.ticks.y, axis.ticks.y.left,
axis.ticks.y.right, axis.ticks.theta, axis.ticks.r, axis.minor.ticks.x.top,
axis.minor.ticks.x.bottom, axis.minor.ticks.y.left, axis.minor.ticks.y.right,
axis.minor.ticks.theta, axis.minor.ticks.r, axis.ticks.length,
axis.ticks.length.x, axis.ticks.length.x.top, axis.ticks.length.x.bottom,
axis.ticks.length.y, axis.ticks.length.y.left, axis.ticks.length.y.right,
axis.ticks.length.theta, axis.ticks.length.r, axis.minor.ticks.length,
axis.minor.ticks.length.x, axis.minor.ticks.length.x.top,
axis.minor.ticks.length.x.bottom, axis.minor.ticks.length.y,
axis.minor.ticks.length.y.left, axis.minor.ticks.length.y.right,
axis.minor.ticks.length.theta, axis.minor.ticks.length.r,
axis.line, axis.line.x, axis.line.x.top, axis.line.x.bottom,
axis.line.y, axis.line.y.left, axis.line.y.right, axis.line.theta,
axis.line.r, legend.background, legend.margin, legend.spacing,
legend.spacing.x, legend.spacing.y, legend.key, legend.key.size,
legend.key.height, legend.key.width, legend.key.spacing,
legend.key.spacing.x, legend.key.spacing.y, legend.key.justification,
legend.frame, legend.ticks, legend.ticks.length, legend.axis.line,
legend.text, legend.text.position, legend.title, legend.title.position,
legend.position, legend.position.inside, legend.direction,
legend.byrow, legend.justification, legend.justification.top,
legend.justification.bottom, legend.justification.left,
legend.justification.right, legend.justification.inside,
legend.location, legend.box, legend.box.just, legend.box.margin,
legend.box.background, legend.box.spacing, panel.background,
panel.border, panel.spacing, panel.spacing.x, panel.spacing.y,
panel.grid, panel.grid.major, panel.grid.minor, panel.grid.major.x,
panel.grid.major.y, panel.grid.minor.x, panel.grid.minor.y,
panel.ontop, panel.widths, panel.heights, plot.background,
plot.title, plot.title.position, plot.subtitle, plot.caption,
plot.caption.position, plot.tag, plot.tag.position, plot.tag.location,
plot.margin, strip.background, strip.background.x, strip.background.y,
strip.clip, strip.placement, strip.text, strip.text.x, strip.text.x.bottom,
strip.text.x.top, strip.text.y, strip.text.y.left, strip.text.y.right,
strip.switch.pad.grid, strip.switch.pad.wrap, complete = FALSE,
validate = TRUE)
{
....
}As a test, I copied the definition of the theme_sub_axis_y() function into the global environment, created a function with the same name but added the three dots to its arguments, and it seems that the warning disappears.
theme_sub_axis_y <-
function (..., title, text, ticks, ticks.length, line, minor.ticks.length) {
subtheme(find_args(), "axis.", ".y")
}
Ah great, thanks for finding this, I can confirm. Adding ... as an argument also ensures that we may add or remove arguments in the future, so it would actually solve 2 problems instead of 1.

