- Trending Categories
- Data Structure
- Operating System
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to write text and output it as a text file using R?
The easiest way to write text and obtain it as an output is done by using writeLines function and cat function, and the output of these functions are connected with the help fileConn and sink.
> fileConn<-file("example1.txt") > writeLines(c("TutorialsPoint","SIMPLY EASY LEARNING"), fileConn) > close(fileConn)
We can do the same and view these files in R as follows −
> fileConn <- file("example2.txt") > writeLines(c(paste("TutorialsPoint", "E-learning"),"2006", "Video Courses", "Tutorials", "Books"), fileConn) > close(fileConn) > file.show("example.txt")
Using sink function
> sink("example3.txt") > cat("TutorialsPoint", "E-learning") > cat("
") > cat("2006") > cat("
") > cat("Video Courses") > cat("
") > cat("Tutorials") > cat("
") > cat("Books") > sink()
Using only cat function
> cat("TutorialsPoint E-learning", "2006", "Video Courses", "Tutorials", "Books",file="outfile.txt",sep="
") > cat("Books",file="outfile.txt",append=TRUE)
You can find these files in documents folder of your system.
- How to extract text from a web page using Selenium and save it as a text file?
- How to write a single line in text file using Python?
- How to write multiple lines in text file using Python?
- How to write text outside plot using ggplot2 in R?
- How to write a text file in Selenium with python?
- How to append text to a text file in C++?
- How to search and replace text in a file using Python?
- How to output colored text to a Linux terminal?
- How to create a text file and insert data to that file on Android using Kotlin?
- How to save matrix created in R as tables in a text file with column names same as the matrix?
- How to find and replace the word in a text file using PowerShell?
- Text and File processing using sed Linux Commands
- How to Copy Odd Lines of Text File to Another File using Python
- How to find and replace within a text file using Python?\n\n\n
- How to read a text file with C++?