eval(expr,envir,enclos)中的错误:找不到函数“eval” [英] Error in eval(expr, envir, enclos) : could not find function "eval"
问题描述
eval(expr,envir,enclos)中的错误:我正在处理Kaggle Digit Recognizer问题。当我尝试给定的代码时,出现错误。找不到函数eval
$ p $ library $ g $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ )
train< - data.frame(read_csv(../input/trace.csv))
labels < - train [,1]
features< ; - train [, - 1]
rowsToPlot< - sample(1:nrow(train),49)
rowToMatrix< - function(row){
强度< - as.numeric(row)/ max(as.numeric(row))
return(t(matrix((rgb(intensity,intensity,intensity)),28,28)))$ 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)),尺度)
x_rng < - 范围(边界$ x,na.rm =真)
y_rng < - 范围(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 <看看最新的ggplot2 /R/geom-raster.r#L46rel =nofollow>代码在github上。 ggproto
现在会替换 proto
以及其他更改。
下面的代码应该可以正常工作。
GeomRasterDigit< - ggproto(ggplot2 ::: GeomRaster,expr = {
draw_groups < - 函数(。,数据,比例尺,坐标,数字,...){
边界< - 坐标转换(坐标,数据帧(x = c(-Inf,Inf),y = c (边界$ x,na.rm =真)
y_rng< - 范围(边界$ 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
这是一个很好的阅读。
I am working on the Kaggle Digit Recognizer problem.when I tried the given code I got the error.
Error in eval(expr, envir, enclos) : could not find function "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
Take a look at the latest ggplot2 code on github. ggproto
now replaces proto
among other changes.
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.
这篇关于eval(expr,envir,enclos)中的错误:找不到函数“eval”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!