Reputation: 489
I have some objects in R that can change from time to time:
beginning <- "Our_Office_Preface"
query_type <- "PA_"
date <- "2018_06_08_"
office_query_type <- "dis_"
input_FY <- 2015
filename <- paste(beginning,"",query_type,"",date,"",office_query_type,"",input_FY,sep="")
and I'm trying to write a dataframe as a tab delimited txt file. I'm trying to save it as filename
and having a hard time making it tab delimited.
df <- data.frame(name=c('Inst1','Inst2','Inst3','Inst4','Inst5','Inst6','Inst7','Inst8','Inst9','Inst10'), num=c(1,5,6,7,4,6,5,7,8,4))
these two lines
write.table(df , file=paste(filename, ".txt", sep="\t", quote = FALSE))
write.table(df , file=paste(filename, ".txt", sep="\t"), append = FALSE, quote = FALSE, row.names = FALSE, col.names = TRUE)
both produced this error
Error in file(file, ifelse(append, "a", "w")) : cannot open the connection
Could I get some assistance?
Upvotes: 1
Views: 175
Reputation: 1784
You just misplaced your closing parenthesis on the paste
function.
sep = "\t"
is a write.table
argument and it's being passed to paste
instead.
Close the paste
function after ".txt"
and it should work.
write.table(df , file=paste(filename, ".txt"), sep="\t", quote = FALSE)
Upvotes: 1