1

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?

1 Answer 1

1

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)
Sign up to request clarification or add additional context in comments.

1 Comment

Derp! I knew it would be something like that. Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.