In the code below inA
in third line from the bottom of the function is not recognized/evaluated properly. I get
Error in parse(text = inA) : object 'inA' not found".
inA
is recognized just fine in the two other lines above that where it is used. I have tried a LOT of permutations.
gcplot2 <- function (inraw,inA,inB){
inwork <- ddply(inraw,
.( eval(parse(text=inA)), eval(parse(text=inB)),BestYr),
summarize,
cases=sum(Cases,na.rm=TRUE),
pop=sum(Pop,na.rm=TRUE),
rate=round(100000*cases/pop,2))
names(inwork)[1] <- inA
names(inwork)[2] <- inB
#problem "inA" is here
x <- ggplot(inwork,aes(BestYr,rate, color=eval(parse(text=inA))))
x <- x + geom_line(size=1.5) + facet_wrap(as.formula(paste0("~ ",inB)))
print(x)
}
gcplot2(inraw=gc.full,"NewRace","Region")
Here is a small sample of the data frame that I hope can be used for a "reproducible example".
dput(temp2)
structure(list(LHJ = c("SACRAMENTO", "YOLO", "SAN BENITO", "COLUSA",
"STANISLAUS", "SAN DIEGO", "SHASTA", "TULARE", "MONTEREY", "KERN"
), BestYr = c(2010L, 2010L, 2010L, 2012L, 2012L, 2012L, 2011L,
2011L, 2010L, 2010L), Sex = structure(c(2L, 2L, 2L, 2L, 2L, 1L,
2L, 2L, 1L, 1L), .Label = c("F", "M"), class = "factor"), RaceEth = structure(c(3L,
4L, 6L, 2L, 6L, 4L, 4L, 2L, 4L, 4L), .Label = c("A", "B", "H",
"O", "U", "W"), class = "factor"), AgeGrp = structure(c(1L, 4L,
5L, 2L, 7L, 2L, 4L, 2L, 3L, 1L), .Label = c("0-9", "10-14", "15-19",
"20-24", "25-29", "30-34", "35-44", "45+", "Unk"), class = "factor"),
Cases = c(NA, 0, 0, 0, 15.652173913, NA, 0, 0, 0, 0), Pop = c(32752.30608,
538.17138648, 444.83561193, 11.107216039, 14186.950585, 5486.3069863,
338.26814356, 245.3890448, 535.23711331, 2278.6798429), NewRace = c("Hispanic",
"Other", "White", "Black", "White", "Other", "Other", "Black",
"Other", "Other"), Region = structure(c(6L, 6L, 3L, 5L, 3L,
8L, 5L, 3L, 2L, 3L), .Label = c("Bay Area", "Central Coast",
"Central Inland", "Los Angeles", "Northern", "Sacramento Area",
"San Francisco", "Southern"), class = "factor")), .Names = c("LHJ",
"BestYr", "Sex", "RaceEth", "AgeGrp", "Cases", "Pop", "NewRace",
"Region"), row.names = c(41377L, 67523L, 42571L, 7418L, 59857L,
45051L, 54102L, 64260L, 32612L, 17538L), class = "data.frame")