I am working on the Kaggle Digit Recognizer problem.when I tried the given code I got the error.
我正在研究Kaggle Digit Recognizer问题。当我尝试给定的代码时,我收到了错误。
Error in eval(expr, envir, enclos) : could not find function "eval"
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)
I am getting the error when I run the following segment.
我运行以下段时收到错误。
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 for the complete code : https://www.kaggle.com/benhamner/digit-recognizer/example-handwritten-digits/code
链接完整代码:https://www.kaggle.com/benhamner/digit-recognizer/example-handwritten-digits/code
1 个解决方案
#1
4
Take a look at the latest ggplot2 code on github. ggproto
now replaces proto
among other changes.
看看github上最新的ggplot2代码。 ggproto现在替换其他更改中的proto。
The code below should work fine.
下面的代码应该可以正常工作。
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)
}
})
There is a vignette about ggproto
that is a good read.
有一个关于ggproto的小插图是一个很好的阅读。
#1
4
Take a look at the latest ggplot2 code on github. ggproto
now replaces proto
among other changes.
看看github上最新的ggplot2代码。 ggproto现在替换其他更改中的proto。
The code below should work fine.
下面的代码应该可以正常工作。
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)
}
})
There is a vignette about ggproto
that is a good read.
有一个关于ggproto的小插图是一个很好的阅读。