2016-02-17 16 views
5

Tôi đang làm việc trên vấn đề Nhận dạng chữ số Kaggle. Khi tôi thử mã đã cho, tôi nhận được lỗi.Lỗi trong eval (expr, envir, enclos): không thể tìm thấy hàm "eval"

Lỗi trong eval (expr, envir, enclos): không thể tìm thấy chức năng "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) 

Tôi nhận được thông báo lỗi khi tôi chạy phân khúc tiếp theo.

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

liên kết cho đoạn code hoàn chỉnh: https://www.kaggle.com/benhamner/digit-recognizer/example-handwritten-digits/code

+0

có thể là sự không tương thích giữa mã này và phiên bản mới nhất của ggplot2 ... –

+0

Có cách nào để giải quyết vấn đề này không? –

+0

Chỉ đơn giản là 'proto (ggplot2 :: GeomRaster)' tái tạo cùng một lỗi. – kdauria

Trả lời

4

Hãy nhìn vào các ggplot2 mới nhất code trên github. ggproto hiện thay thế proto trong số các thay đổi khác.

Mã bên dưới sẽ hoạt động tốt.

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ó một vignette về ggproto đó là một đọc tốt.

Các vấn đề liên quan