问题描述:

I have a filename Im using to do stuff with; it is a variable representing the path Im interested in. At the end of the script I would like to do some sed cleanup on it but I dont know how to pass the variable to it. Here's what I have:

library(gdata)

filename = file.choose()

mydata = read.xls(file.choose())

newdata <- subset(mydata[1:3])

filename=paste(filename,".bed")

write.table(newdata,filename,sep="\t",row.names=FALSE, col.names=FALSE)

system("sed -i '' 's/\"//g'" filename)

but I get the error as follows-

Error: unexpected symbol in "system("sed -i '' 's/\"//g'" filename"

Im sure its do do with some kind of "" lunacy but can't figure it out

网友答案:

Try using paste:

system(paste("sed -i '' 's/\"//g'",filename))

Also, you might want to use paste0 instead of paste (or add the sep="" argument) when you add the extension to filename, right now it adds a space between the filename and extension.

filename=paste0(filename,".bed")
相关阅读:
Top