1

I would like to train a model and give it a name. I would like to use this name as character as well to create a text file with model summary. So I created a function as below

C50Training<-function(ModeName,DF_Trai,Form,
                      Str_PathSum){
  library(C50);

  ModeName<-C5.0(formula=Form,data=DF_Trai);
  capture.output(summary(ModeName),file=paste(Str_PathSum,"/Summ",ModeName,".txt",sep=""));
}

In the funtion I want to use ModeName as characters. I tried to run it but it does not work. ModelName is a list in this case. How can I use ModelName as character?

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
davidzxc574
  • 471
  • 1
  • 8
  • 21
  • Hi, we can't do much with your code if you don't [provide any data](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610). – jay.sf Mar 20 '19 at 08:25

1 Answers1

1

To change a variable name to string, you can use deparse and substitute, as follows:

deparse(substitute(ModeName))

It return "ModeName" that can be part of your file path.

I tried this. It works.

ModeName=c(1,2,3)
f<-function(ModeName){
  print(paste("/Summ",deparse(substitute(ModeName)),".txt",sep=""))
}
f(ModeName)

and this works too:

ModeName=c(1,2,3)
f<-function(list){
  print(paste("/Summ",deparse(substitute(list)),".txt",sep=""))
}
f(ModeName)