Hi Mateo,
not sure if I totally get what you're after, but maybe this helps:
SharpeRatio.annualized <- function(roc){
print("I'm computing the Sharpe Ratio")
return(9999)
}
MyF <- function(Tic, price){
print("Option 1")
expr <- expression(Ratio.Tic <- SharpeRatio.annualized(roc))
print(expr)
eval(expr)
print(Ratio.Tic)
rm(Ratio.Tic)
print("Option 2")
expr <- paste("Ratio.", quote(Tic), " <-
SharpeRatio.annualized(roc)", sep="")
print(expr)
eval(parse(text=expr))
print(Ratio.Tic)
rm(Ratio.Tic)
print("Option 3")
frmls <- formals("MyF")
expr <- sapply(names(frmls), function(x){
expr <- substitute(NAME <- SharpeRatio.annualized(roc),
list(NAME=as.name(paste("Ratio", x, sep="."))))
return(expr)
})
print(expr)
sapply(expr, eval, envir=environment())
print("Ratio.Tic")
print(Ratio.Tic)
print("Ratio.price")
print(Ratio.price)
}
MyF()
Have fun with R!
Regards,
Janko
On 23.05.2011 23:31, MatAra wrote:> Hello,
>
> I am stuck in a relatively simple procedure and was wondering if anybody
> knows the answer. I am a relatively new R user.
>
> How do I use an argument of a custom function in the name of a dataset in
R?
> For example, I have the function:
>
> MyF<- function(Tic, price){
> xxxxx
> xxxxx
> xxxxx
> Ratio.Tic<- SharpeRatio.annualized(roc)
> }
>
> I would like to have a dataset that's labelled Ratio.MSFT, Ratio.XOM,
> Ratio.IBM...etc. The objective is to append multiple Ratio.Tic datasets
that
> contains all the ratios in one single data.
> Thanks in for your time!
> Mateo
>
>
> --
> View this message in context:
http://r.789695.n4.nabble.com/Passing-function-arguments-to-dataset-names-tp3545567p3545567.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
[[alternative HTML version deleted]]