2016-02-17 10 views
5

私はKaggle Digit Recognizer問題に取り組んでいます。 evalの中eval(expr、envir、enclos)のエラー:関数 "eval"を見つけることができません

エラー(exprの、ENVIR、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を見てみましょう。他の変更の中でもは現在protoを置き換えます。ggproto

以下のコードは正常に動作します。

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があります。

関連する問題