Reputation: 477
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.
Upvotes: 1
Views: 3251
Reputation: 1178
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.
Upvotes: 3