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,100 points
26 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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,700 points

Related Questions In Data Analytics

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,100 points
55 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 ANMOL
• 3,620 points

edited Aug 28, 2018 by Vardhan 23 views
0 votes
1 answer
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,700 points
23 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,700 points
61 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,700 points
35 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,700 points
32 views
0 votes
1 answer

How to write lines to a text file in R?

It is easy and simple: fileConn<-file("abc.txt") writeLines(c("H ...READ MORE

answered Apr 16, 2018 in Data Analytics by DeepCoder786
• 1,700 points
544 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,700 points
90 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.