Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R json,incomplete final line found

Tags:

json

r

My problem: R json,incomplete final line found

My effort: I followed 'Incomplete final line' warning when trying to read a .csv file into R

I used this site to check my files validity. It is data from my facebook news feed collected using graph api.

My code:

library("rjson")
work<-"C:/ContainingFolder/"
json_data <- fromJSON(paste(readLines(paste0(work,"SunwayFB.txt")), collapse=""))

My error:

Warning message:
In readLines(paste0(work, "SunwayFB.txt")) :
  incomplete final line found on 'C:/ContainingFolder/SunwayFB.txt'
like image 814
FailedMathematician Avatar asked Jan 27 '14 09:01

FailedMathematician


3 Answers

It works without any errors if you read the file with fromJSON instead of readLines.

fp <- file.path(work, "SunwayFB.txt")
json_data <- fromJSON(file = fp)

By the way: For the readLines way, you have to add a new line at the end of the file.

like image 91
Sven Hohenstein Avatar answered Oct 31 '22 15:10

Sven Hohenstein


You can ignore the warning message.

readLines(paste0(work,"SunwayFB.txt"))

add warn field.

readLines(paste0(work,"SunwayFB.txt"), warn=FALSE)

like image 45
Junhee Shin Avatar answered Oct 31 '22 13:10

Junhee Shin


In most cases, Incomplete final line warnings can be averted by appending a new line to the file you are trying to open. Just go to the end of file -> press enter -> Save the file -> re-run whatever command you are using to load it in R and it shall show no warning.

like image 31
smaug Avatar answered Oct 31 '22 15:10

smaug