2016-02-17 13 views
5

Sto lavorando al problema di Kaggle Digit Recognizer. Quando ho provato il codice indicato ho ricevuto l'errore.Errore in eval (expr, envir, enclos): impossibile trovare la funzione "eval"

Error in eval (espressione, envir, enclos): non riusciva a trovare la funzione "eval"

library(ggplot2) 
library(proto) 
library(readr) 
train <- data.frame(read_csv("../input/train.csv")) 

labels <- train[,1] 
features <- train[,-1] 

rowsToPlot <- sample(1:nrow(train), 49) 

rowToMatrix <- function(row) { 
    intensity <- as.numeric(row)/max(as.numeric(row)) 
    return(t(matrix((rgb(intensity, intensity, intensity)), 28, 28))) 
} 

geom_digit <- function (digits, labels) GeomRasterDigit$new(geom_params = 
list(digits=digits),stat = "identity", position = "identity", data = NULL, 
inherit.aes = TRUE) 

sto ottenendo l'errore quando ho eseguito il seguente segmento.

GeomRasterDigit <- proto(ggplot2:::GeomRaster, expr={ 
draw_groups <- function(., data, scales, coordinates, digits, ...) { 
bounds <- coord_transform(coordinates, data.frame(x = c(-Inf, Inf), y = c(
- Inf, Inf)), scales) 
x_rng <- range(bounds$x, na.rm = TRUE) 
y_rng <- range(bounds$y, na.rm = TRUE) 
rasterGrob(as.raster(rowToMatrix(digits[data$rows,])), x_rng[1], y_rng[1], 
diff(x_rng), diff(y_rng),default.units = "native", just =c("left","bottom"), 
interpolate = FALSE) 
} 
}) 

link per il codice completo: https://www.kaggle.com/benhamner/digit-recognizer/example-handwritten-digits/code

+0

probabilmente un'incompatibilità tra questo codice e la versione più recente di ggplot2 ... –

+0

C'è un modo per risolvere questo? –

+0

Semplicemente 'proto (ggplot2 :: GeomRaster)' riproduce lo stesso errore. – kdauria

risposta

4

Date un'occhiata al più tardi ggplot2 code su github. ggproto sostituisce ora proto tra le altre modifiche.

Il codice seguente dovrebbe funzionare correttamente.

GeomRasterDigit <- ggproto(ggplot2:::GeomRaster, expr={ 
draw_groups <- function(., data, scales, coordinates, digits, ...) { 
bounds <- coord_transform(coordinates, data.frame(x = c(-Inf, Inf), y = c(
- Inf, Inf)), scales) 
x_rng <- range(bounds$x, na.rm = TRUE) 
y_rng <- range(bounds$y, na.rm = TRUE) 
rasterGrob(as.raster(rowToMatrix(digits[data$rows,])), x_rng[1], y_rng[1], 
diff(x_rng), diff(y_rng),default.units = "native", just =c("left","bottom"), 
interpolate = FALSE) 
} 
}) 

C'è un vignette su ggproto che è una buona lettura.