如何从r中查找和替换外部文本文件

如何从r中查找和替换外部文本文件,r,R,我已经在r中创建了一个文件,其中包含一些结果 此文件需要在另一个文本文件中引用,该文本文件是另一个程序的配置文件 因此,我想了解如何从R中查找和替换外部文本文件。特别是查找文本 #CustomFile1Here file="" 到目前为止,我在R #Create the file write.table(mydata,"blabla.circos.txt",quote=FALSE,row.names=FALSE,col.names=FALSE,sep="\t") #Assign the fi

我已经在r中创建了一个文件,其中包含一些结果

此文件需要在另一个文本文件中引用,该文本文件是另一个程序的配置文件

因此,我想了解如何从R中查找和替换外部文本文件。特别是查找文本

#CustomFile1Here
file=""
到目前为止,我在R

#Create the file
write.table(mydata,"blabla.circos.txt",quote=FALSE,row.names=FALSE,col.names=FALSE,sep="\t")

#Assign the filename to be inserted into the config file
filename1="blabla.circos.txt"

#insert the filename just created into the config file at the line (and between the "" in
##CustomFile1Here
##file=""
system(paste("grep ^#CustomFile1Here\nfile='",filename1))

在我运行这个程序的时候,一切都停滞了。这是因为双引号还是整件事都不正确?

如果mydata实际上是一个表,您只需将整个文件作为data.frame读取,然后找到名为filename1的列/行即可。你试过了吗?我不太明白你的答案。我想将数据帧写入的文件名和路径读入另一个外部文本文件。换句话说。什么是mydata?名单?一个data.frame?mydata是一个DataFrame哦,我错了,我以为mydata和filename1在同一个文件上。