How to import text file as a single character string

0 votes

How do we import a plain text file as a single character string in R?

The Method I tried:

scan("temp.txt",what = "character",sep=NULL)

this method creates char list, is there any other way ?

Apr 23, 2018 in Data Analytics by DataKing99
• 8,240 points
1,045 views

1 answer to this question.

0 votes

First way:

rd<-readChar("temp.txt",file.info("temp.txt")$size)

Another way:

install.packages("readr")
library(readr)
mystring <- read_file("temp.txt")
answered Apr 23, 2018 by DeepCoder786
• 1,720 points

Related Questions In Data Analytics

0 votes
1 answer

How to import and clean a text file into dataframe in R?

You can use readLines() or read.table() depending ...READ MORE

answered Jul 16, 2019 in Data Analytics by anonymous
5,985 views
0 votes
1 answer

How to evaluate expression given as a string in R?

The eval() function evaluates an expression, but "5+5" is a string, ...READ MORE

answered Jun 7, 2018 in Data Analytics by DataKing99
• 8,240 points
4,163 views
0 votes
1 answer

How can I import a file in R without giving the destination/file path to the specified file?

You can use the window explorer to ...READ MORE

answered Aug 28, 2018 in Data Analytics by Abhi
• 3,720 points

edited Aug 28, 2018 by Vardhan 2,425 views
0 votes
1 answer

By using dpylr package sum of multiple columns

Basically here we are making an equation ...READ MORE

answered Apr 5, 2018 in Data Analytics by DeepCoder786
• 1,720 points
1,993 views
0 votes
1 answer

How to convert a text mining termDocumentMatrix into excel or csv in R?

By assuming that all the values are ...READ MORE

answered Apr 5, 2018 in Data Analytics by DeepCoder786
• 1,720 points
1,605 views
0 votes
1 answer

In a dpylr pipline how to use sample and seq?

For avoiding rowwise(), I prefer to use ...READ MORE

answered Apr 6, 2018 in Data Analytics by DeepCoder786
• 1,720 points

edited Jun 9, 2020 by Gitika 892 views
0 votes
1 answer

How to create a list of Data frames?

Basically all we have to do is ...READ MORE

answered Apr 9, 2018 in Data Analytics by DeepCoder786
• 1,720 points
997 views
0 votes
3 answers

How to write lines to a text file in R?

sink("outfile.txt") cat("hello") cat("\n" ...READ MORE

answered May 24, 2019 in Data Analytics by anonymous
18,533 views
0 votes
1 answer

How to import data from a Json file into R?

Easy and simple: library("rjson") json_file <- "file_name" json_data <- fromJSON(file=json_file)) or ...READ MORE

answered Apr 26, 2018 in Data Analytics by DeepCoder786
• 1,720 points
2,053 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP