I have a number of objects I would like to plot in R and save them to my directoy. To assign the name of each graph I need to be able to obtain the name (as String?) of the object to plot.
An example is:
setwd("C:/.../mydirectory/")
myname <- myobjectname(myobject) **I want to obtain the string of "myobject"**
png(paste(myname, ".png", sep=""))
myGraphingFunction(myobject)
dev.off()
I have tried the:
myobjectname <- function(v1){
deparse(substitute(v1))
}
Which does what I want to do and returns the string I want. Nevertheless, when using it in a loop or in the above graph case it is not working.
I have a function with the argument "month" which will be substituted by "january" or "february", etc. E.G. When using the function:
myobjectname <- function(month)
Within a loop, altough the variable month is now January (or whatever), the string I get is always "month".
Summarizing:
> deparse(substitute(january))
[1] "january"
> month <- january
> deparse(substitute(month))
[1] "month"
Any hint on how for the second case to give back "january" ?
Thanks