1
votes


I'm currently learning Sentiment Analysis in r ,

i got stuck in part how to properly read and import the data into my case,

i want to know how to read data using scan() in r ,
but how to make that it gonna read the white space too between string in one row from the txt

case :

for example,

positive.txt contain :

Not Strong


*the string above written inside txt file without separated semi colon or comma, just line spacing \n


so, i read that txt formatted file by using this in r :

positive -> scan('positive.txt', what = ' ', sep="\n")

there's no error,

but after i check,
the main problem is read the imported file by using scan() will read the white space between character,
so from input positive.txt file:

1) Not Strong

the result using scan() into positive.txt file in r will end up like this :
1) Not
2) Strong

What i expected is :
how to make scan() file in r keep maintain the white space from character inside positive.txt :
1) Not Strong

the result i expected is still :
1) Not Strong

*note, the number 1 is only some guide like some kind index, to help understand this problems.

1
I think you want readLines instead - rawr

1 Answers

0
votes
$ cat /tmp/file.txt
this is line 1
this is line 2
this is line 3

in R:

file.contents <- readLines('/tmp/file.txt')

file.contents

# [1] "this is line 1" "this is line 2" "this is line 3"

Good luck with Sentiment Analysis, it's a great topic!