2016-02-17 6 views
5

मैं Kaggle Digit Recognizer समस्या पर काम कर रहा हूं। जब मैंने दिए गए कोड को आजमाया तो मुझे त्रुटि मिली। eval मेंeval में त्रुटि (expr, envir, enclos): फ़ंक्शन "eval" नहीं मिला

त्रुटि (expr, माहौल, enclos): नहीं पा सके समारोह "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) 

जब मैं निम्नलिखित खंड चलाने मैं त्रुटि हो रही है। पूरा कोड के लिए

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) 
} 
}) 

लिंक: https://www.kaggle.com/benhamner/digit-recognizer/example-handwritten-digits/code

+0

शायद इस कोड और ggplot2 के नवीनतम संस्करण के बीच एक असंगतता ... –

+0

क्या इसे हल करने का कोई तरीका है? –

+0

बस 'proto (ggplot2 :: geomRaster) 'एक ही त्रुटि को पुन: उत्पन्न करता है। – kdauria

उत्तर

4

GitHub पर नवीनतम ggplot2 code पर एक नजर डालें। ggproto अब अन्य परिवर्तनों के बीच proto को प्रतिस्थापित करता है।

नीचे दिया गया कोड ठीक काम करना चाहिए।

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) 
} 
}) 

के बारे में ggproto एक अच्छा पढ़ा है कि एक vignette नहीं है।

संबंधित मुद्दे