Howdy, I have searched the lists and can not seem to find a solution to my problem. I need to be able to dynamically modify a string inside a function to build a new function. "sub" replaces with a quoted string... and "parse" of "sub" returns expression... How can I get an unquoted string from a regex to stick into a "body" of a function?
Thanks for your help! dan # Original Function fsong=function(x){ song=paste("my name is fuka,",x) return(song) } fsong("I live on the second floor") # # Copy and modify using "sub" returns quoted string with escaped quotes # internally... as expected.. which can not be evaluated. nsong=fsong body(nsong)[[grep("fuka",body(nsong))]]= sub("fuka","muka",list(body(fsong)[[grep("fuka",body(fsong))]])) nsong("I live on the second floor") # broken # # Copy and modify with "parse" of "sub", returns expression.. but without quotes, # o getting closer. # nsong=fsong body(nsong)[[grep("fuka",body(nsong))]]= parse(text=sub("fuka","muka",list(body(fsong)[[grep("fuka",body(fsong))]]))) ______________________________________________ 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.