I’ve written a function that contains multiple subfunctions. The subfunctions are all exactly like the the one below:
Lfunction <- function(mydata, mydata.hex) {
mydata.Lest <- Lest(mydata)
mydata.hex.Lest <- Lest(mydata.hex)
pdf(file="Lplot.pdf")
plot(mydata.Lest, xlim=c(0,200), ylim=c(0,200), main="L Function", xlab="Distance Between Particles (r)", ylab=expression(paste(L(r))), legend = legend(x=165, y=30, c("CSR", "mydata", "mydata.hex"), lty = c(2,1,4), col = c("red", "black","blue"), border = "black"))
plot(mydata.hex.Lest, xlim=c(0,200), ylim=c(0,200), add = TRUE, lty = c(4,2), col = c("blue", "red"))
dev.off()
}
It basically just plots the F function for my two point patterns (mydata and mydata.hex) and exports the image as a PDF to a designated folder on my computer.
For some reason, I’m getting the following error message:
Error in !is.null(legend) && legend : invalid ‘y’ type in ‘x && y’
Now, I’ve gotten this message every time I’ve altered the legend on the plot of an F, G, J, K, L or PCF function. I figured that it was irrelevant since it still produces the graph, and in the location I specified.
The problem is that this error causes my large function (which runs roughly 10 functions like the one shown above) to stop evaluating. The large function looks like this:
GenPDFs <- function(file_name){
mydata <- CreatePPP(file_name)
mydata.hex <- GenHexLat()
Density(mydata)
Lfunction(mydata, mydata.hex)
LfunctionGDS(mydata, mydata.hex)
Ffunction(mydata, mydata.hex)
FfunctionGDS(mydata, mydata.hex)
Gfunction(mydata, mydata.hex)
GfunctionGDS(mydata, mydata.hex)
Jfunction(mydata, mydata.hex)
Kfunction(mydata, mydata.hex)
KfunctionGDS(mydata, mydata.hex)
PCFfunction(mydata, mydata.hex)
#for (i in 1:30) {
# dev.off()
# }
}
Thus, I have to manually enter the values into each function.
Does anyone know how to get rid of this warning message? Is there any way to turn it off or negate it from appearing? Or, if you’ve had this error message, do you know how to fix it? For some reason no matter what syntax I use, it produces this error message.
Could you be passing a function call to the (possibly) non-existent ‘legend’ argument of plot? Try this instead: