Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
+2 votes
2 views
in R Programming by (7.3k points)
edited by

In the R scripting language, how do I write lines of text, e.g. the following two lines

Hello

World

to a file named "output.txt"?

2 Answers

+2 votes
by
edited by

You can use the writeLines() function in R to write lines of text to a file as follows:

fileout <-file("output.txt")

writeLines(c("Hello","World"), fileout)

close(fileout)

The output.txt file will be stored in your current working directory. 

If you want to explore more in R programming then watch this R programming tutorial for beginners:

+2 votes
by (107k points)
edited by

It is easy and simple to perform, refer to the following statements:

fileConn<-file("abc.txt")

writeLines(c("Hello","World"), fileConn)

close(fileConn)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...