Error in Eval(Expr, Envir, Enclos) - Contradiction

Error in eval(expr, envir, enclos) - contradiction?

I am not sure whether this is what you want, but it might help. I modified agstudy's code:

spy <- read.csv(file= 'http://ichart.finance.yahoo.com/table.csv?s=SPY&d=11&e=1&f=2012&g=d&a=0&b=29&c=1993&ignore=.csv', header= T)

library(ggplot2)
library(RColorBrewer)

plot.prices <- function(df) {

df$Date <- as.Date(df$Date, format= "%Y-%m-%d")

g <- ggplot(df, aes_string(x='Date', y= colnames(df)[3])) +
geom_point(colour= brewer.pal(12,"Set3")[1], size=1)

gg <- g + geom_point(aes_string(x='Date', y= colnames(df)[4]),
colour= brewer.pal(12,"Set3")[2], size=1)
gg
}

plot.prices(spy)

Here is code without using brewer.pal:

library(ggplot2)

spy <- read.csv(file= 'http://ichart.finance.yahoo.com/table.csv?s=SPY&d=11&e=1&f=2012&g=d&a=0&b=29&c=1993&ignore=.csv', header= T)

plot.prices <- function(df) {

df$Date <- as.Date(df$Date, format= "%Y-%m-%d")

g <- ggplot(df, aes_string(x='Date', y= colnames(df)[3])) +
geom_point(colour= 'green', fill='green', size=1)

gg <- g + geom_point(aes_string(x='Date', y= colnames(df)[4]),
colour= 'black', fill='black', size=1)
gg
}

plot.prices(spy)

dplyr Error in eval(expr, envir, enclos) : object '.' not found

Actually the error simply comes from your way of using the piping in the first command. The . (dot) refers to the previous result in the pipeline but there is nothing before your filter so it gives the error!

To get it work you can take the data.frame out of the filter function:

closing <- survey %>% filter(.[[47]] != 0, .[[48]] >= 10) %>% ...

I tested it with another dataset.

Error in eval(expr, envir, enclos) : object 'Tribe' not found

You want the colour of your points to vary by the variable state, so it should be inside the aes:

 geom_point(aes(colour = State))

Anything outside of the aes is constant, so, colour=red or size=2.

Error in eval(expr, envir, enclos) : could not find function

I'm not sure if this is intended behavior or a bug, but the following seems to work:

f <- function(agg.fun) {
dcast(
DT,
time ~ variable,
fun.aggregate = eval(substitute(agg.fun)),
# ^^^^^^^^^^^^^^^^^^^^^^^^^
na.rm = TRUE
)
}

f(mean)
# time weight
# 1: 0 41.06000
# 2: 2 49.22000
# 3: 4 59.95918
# 4: 6 74.30612
# 5: 8 91.24490
# 6: 10 107.83673
# 7: 12 129.24490
# 8: 14 143.81250
# 9: 16 168.08511
# 10: 18 190.19149
# 11: 20 209.71739
# 12: 21 218.68889

library(data.table)
DT <- melt(
setnames(
as.data.table(ChickWeight),
names(ChickWeight), tolower(names(ChickWeight))
),
id = 2:4
)

Error in eval(expr, envir, enclos) : object not found

Don't know why @Janos deleted his answer, but it's correct: your data frame Train doesn't have a column named pre. When you pass a formula and a data frame to a model-fitting function, the names in the formula have to refer to columns in the data frame. Your Train has columns called residual.sugar, total.sulfur, alcohol and quality. You need to change either your formula or your data frame so they're consistent with each other.

And just to clarify: Pre is an object containing a formula. That formula contains a reference to the variable pre. It's the latter that has to be consistent with the data frame.



Related Topics



Leave a reply



Submit