Closed levialtringer closed 4 years ago
RESOLVED: I resolved the error by specifying the data
argument in the cplot()
function. See the code below.
my_cplot_function <- function(sepal_length_limits=NULL) {
if (is.null(sepal_length_limits)){
temp_df <- iris
} else {
temp_df <- subset(iris, Sepal.Length>=sepal_length_limits[1] & Sepal.Length<=sepal_length_limits[2])
}
m <- lm(Sepal.Length ~ Sepal.Width, data = temp_df)
return(cplot(m, data = temp_df))
}
my_cplot_function(sepal_length_limits = c(4,6))
I also think that the initial error is specific to Windows machines.
Please specify whether your issue is about:
If you are reporting (1) a bug or (2) a question about code, please supply:
traceback()
run immediately after the error occurssessionInfo()
Hi there! I am trying to call
cplot()
within a function and I am running into an error. Specifically, it seems that data frames which are generated within the function itself cannot be found. Here is a minimal example that makes use of the iris data set in R.First, I generate a function that subsets the iris data set for specified values of "Sepal.Length", runs a simple linear regression, and returns a summary of the output. This function executes without error.
Second, I generate a nearly identical function that subsets the iris data set for specified values of "Sepal.Length" and runs a simple linear regression, but now the function is written to return
cplot(m)
.Executing this function returns the following error:
It seems that
cplot()
is not able to operate on data frames that are generated within functions. Is that correct?Running
traceback()
after the error is produced returns the following:The session information for this example is:
Thank you in advance for any responses that might help me understand what's going on here!