I have something like this:
plot_pca_models <- function(models, id) { library(lattice) splom(models, groups=id) }
and I call it like this:
plot_pca_models(data.pca, log$id)
leading to this error:
Error in eval(expr, envir, enclos) : object 'id' not found
when I call it without a wrapping function:
splom(data.pca, groups=log$id)
it causes this error:
Error in log$id : object of type 'special' is not subsettable
but when I do this:
id <- log$id splom(models, groups=id)
he behaves as expected.
Please can someone explain why he is behaving this way and how to fix him? Thanks.
By the way: I know similar questions here, for example:
but none of them helped me.
edit : As requested, there is a complete plot_pca_models function:
plot_pca_models <- function(data, id, sel=c(1:4), comp=1) {
edit2 : I managed to make the problem reproducible.
require(lattice) my.data <- data.frame(pca1 = rnorm(100), pca2 = rnorm(100), pca3 = rnorm(100)) my.id <- data.frame(id = sample(letters[1:4], 100, replace = TRUE)) plot_pca_models2 <- function(x, ajdi) { splom(x, group = ajdi) } plot_pca_models2(x = my.data, ajdi = my.id$id)
which produce the same error as above.