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

Force arguments that are used in closures #2807

Merged
merged 1 commit into from
Sep 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion R/save.r
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@ plot_dim <- function(dim = c(NA, NA), scale = 1, units = c("in", "cm", "mm"),
dim
}

plot_dev <- function(device, filename, dpi = 300) {
plot_dev <- function(device, filename = NULL, dpi = 300) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For my own education, could you explain why we now need filename = NULL here but in some other cases (e.g., make_summary_fun()) we don't need to add a default?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default doesn't make sense there to me, the function needs arguments or fails. But e.g. manual_scale() could use a better error message.

force(filename)
force(dpi)

if (is.function(device))
return(device)

Expand Down
2 changes: 2 additions & 0 deletions R/scale-manual.r
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ scale_discrete_manual <- function(aesthetics, ..., values) {


manual_scale <- function(aesthetic, values, ...) {
force(values)

pal <- function(n) {
if (n > length(values)) {
stop("Insufficient values in manual scale. ", n, " needed but only ",
Expand Down
2 changes: 2 additions & 0 deletions R/scale-size.r
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ scale_size_discrete <- function(...) {
#' @export
#' @usage NULL
scale_size_ordinal <- function(..., range = c(2, 6)) {
force(range)

discrete_scale(
"size",
"size_d",
Expand Down
6 changes: 6 additions & 0 deletions R/stat-summary-bin.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ StatSummaryBin <- ggproto("StatSummaryBin", Stat,
)

make_summary_fun <- function(fun.data, fun.y, fun.ymax, fun.ymin, fun.args) {
force(fun.data)
force(fun.y)
force(fun.ymax)
force(fun.ymin)
force(fun.args)

if (!is.null(fun.data)) {
# Function that takes complete data frame as input
fun.data <- match.fun(fun.data)
Expand Down