data <- flip_data(data, flipped_aes)
if (length(unique(data$x)) < 2) {
return(new_data_frame())
}
if (is.null(data$weight)) data$weight <- 1
if (is.null(xseq)) {
if (is.integer(data$x)) {
if (fullrange) {
xseq <- scales$x$dimension()
} else {
xseq <- sort(unique(data$x))
}
} else {
if (fullrange) {
range <- scales$x$dimension()
} else {
range <- range(data$x, na.rm = TRUE)
}
xseq <- seq(range[1], range[2], length.out = n)
}
}
if (identical(method, "loess")) {
method.args$span <- span
}
if (is.character(method)) {
if (identical(method, "gam")) {
method <- mgcv::gam
} else {
method <- match.fun(method)
}
}
if (identical(method, mgcv::gam) && is.null(method.args$method)) {
method.args$method <- "REML"
}
base.args <- list(quote(formula), data = quote(data), weights = quote(weight))
model <- do.call(method, c(base.args, method.args))
prediction <- predictdf(model, xseq, se, level)
prediction$flipped_aes <- flipped_aes
flip_data(prediction, flipped_aes)