1translate <- if(!.R. && !under.unix) 2 function(text, old, new, multichar) { 3 if(!missing(multichar) && !multichar) 4 stop('multichar=F not implemented for this operating system') 5 sedit(text, old, new) 6 } else if(FALSE && .R.) function(text, old, new, multichar=FALSE) { 7 if(multichar) stop('multichar=T not implemented under R') 8 k <- chartr(old, new, text) 9 if(is.matrix(text)) k <- matrix(k, nrow=nrow(text)) 10 k 11 } else 12 function(text, old, new, multichar=FALSE) { 13 if(length(old)>1 || (nchar(old)!=nchar(new))) multichar <- TRUE 14 if(length(old)>1 && (length(new)>1 & length(new)!=length(old))) 15 stop("old and new must have same lengths or new must have 1 element") 16 17 if(.R. && !multichar) k <- chartr(old, new, text) ## 27aug03 18 else { 19 if(multichar) command <- paste("sed",paste('-e "s/',old,"/",new,'/g"', 20 sep="", collapse=" ")) 21 else command <- paste("tr \"", old, "\" \"", new, "\"", sep="") 22 ## k <- sys(command, text) replace with next 2 27aug03 23 ## Thanks: <Sebastian.Weber@aventis.com> 24 k <- unlist(lapply(text, function(x, command) { 25 sys(paste("echo \"", x, "\" | ", command, sep="")) }, 26 command=command)) # command= 22feb04 27 ## added command 26jan04; thanks:<Willi.Weber@aventis.com> 28 } 29 if(is.matrix(text)) k <- matrix(k, nrow=nrow(text)) 30 k 31 } 32