当前位置: 动力学知识库 > 问答 > 编程问答 >

Using paste when creating a pdf in R

问题描述:

I want to use the paste function in R when I am saving a file using the pdf function but I get this error:

filename too long in pdf()

What can I do to overcome this problem?

Here is my script:

for (chromo in 1:22){

read.table(paste("locfile_less_chrloc_file_chr", chromo, ".txt.txt" , sep=""))-> chr

t(chr) -> chr_t

as.matrix(chr_t) -> chr_t_m

length(chr_t_m) -> len

pdf(paste("chr",chromo,".pdf", sep=""))

plot(1:len,chr_t_m, type= "l")

dev.off()

}

So, my guess is that the pdf function does not allow the paste function to be used. Is that correct?

Thanks in advance.

网友答案:

Why not store the pdf filename in an extra object?

chr<-"a"
pdfname<-paste0("chr",chr,".pdf")
pdf(file=pdfname)

This works directly by the way: pdf(file=paste0("chr",chr,".pdf"))

To get a shorter filename, try: pdf(file=paste0("chr",names(chr)[1],".pdf"))

Substitute 1 for the appropriate column number.

分享给朋友:
您可能感兴趣的文章:
随机阅读: