3
$\begingroup$

I have problem with loading data into R:

fileUrl <- "http://jadi.net/files/iran_it_status_1394_detail_data_jadi_net.tsv"

download.file(fileUrl , destfile="iran_it_status_1394_detail_data_jadi_net.tsv")

dev <- read.delim("iran_it_status_1394_detail_data_jadi_net.tsv",
              header=TRUE,sep="\t",blank.lines.skip = TRUE,
              na.strings="",fileEncoding="UTF-8",
              stringsAsFactors=FALSE,skipNul = TRUE)

I receive the following error:

Error in read.table(file = file, header = header, sep = sep, quote = quote,  : 
  no lines available in input
  In addition: Warning message:
  In read.table(file = file, header = header, sep = sep, quote = quote,  :
  invalid input found on input connection    'iran_it_status_1394_detail_data_jadi_net.tsv'

Edit: The dataset has 1217 rows and 33 variables.

names(data) <- c("timestamp","age","sex","birth_province","work_province","experience","education",
            "certificate","learn","project","book","language","wish_language","db","desktop_os",
            "wish_os","mobile","env","theme","src_ctrl","tab_space","drink","items","device","title",
            "org_type","org_emp","income","perk","job_contract","job_type","hour_wage","happy")

for language variable I expect this output:

data[1:3,"language"]

C#, Javascript, R, SQL

Java, C#, Javascript, Objective C, Swift, SQL

C#, SQL

Python Solutions are also welcome

$\endgroup$
4
  • $\begingroup$ I'm voting to close this question as off-topic because this is a simple R problem and not data science enough. $\endgroup$
    – Spacedman
    Commented Jun 24, 2016 at 12:13
  • $\begingroup$ Tough one; since R is so commonly used in data science, I could imagine some basic R questions being OK here, even if they might be somewhat better on Stack Overflow. $\endgroup$
    – Sean Owen
    Commented Jun 24, 2016 at 12:50
  • 1
    $\begingroup$ @SeanOwen Useful criterion: If it might be useful to non data-science R users, it should go in Stack Overflow. There's not a single byte of data science in this question. Any R user might want to read a data file like this in. Hence close, move to stack overflow. $\endgroup$
    – Spacedman
    Commented Jun 26, 2016 at 10:43
  • $\begingroup$ Are there non-data-science R users? anything you'd do with R seems like part of data science to me. I think this is more on-topic for SO, but that's different from blocking it here. Some SEs overlap. People have to do stuff like this to do their data science work. $\endgroup$
    – Sean Owen
    Commented Jun 26, 2016 at 11:22

2 Answers 2

2
$\begingroup$

I am able to load the data set like so:

 dev <- read.table("iran_it_status_1394_detail_data_jadi_net.tsv",
                   header=TRUE, sep="\t", blank.lines.skip = TRUE,
                   na.strings="",
                   stringsAsFactors=FALSE, skipNul = TRUE, fill=T, quote="")

Note the removal of the encoding (so that the function "finds" lines in the file), the fill attribute (to allow for a ragged table with empty cells), and the elimination of quotes (apparently there is a misquoted line somewhere near line 585).

This results in a table full of encoded characters - you'll need to know more about the source data to figure out how to work with it, but if you open the file up in a raw text editor (e.g.: Sublime text) you might get some clues:

Character encoding issues?

$\endgroup$
6
  • $\begingroup$ Please see my edit. $\endgroup$
    – Hamideh
    Commented Jun 24, 2016 at 13:13
  • $\begingroup$ Yes, when using the read.table() call above I get 1217 observations of 33 variables $\endgroup$ Commented Jun 24, 2016 at 16:52
  • $\begingroup$ The data is loaded by your script but there is a problem with one of my text variables: language . see my edit. $\endgroup$
    – Hamideh
    Commented Jun 25, 2016 at 15:56
  • $\begingroup$ It doesn't necessarily solve the character encoding issues, but I realized that "#" is the default comment character; comment processing should be ignored: dev <- read.table("iran_it_status_1394_detail_data_jadi_net.tsv", header=TRUE, sep="\t", na.strings="", encoding="UTF-8", stringsAsFactors=FALSE, skipNul = TRUE, fill=T, quote="", comment.char="") $\endgroup$ Commented Jun 26, 2016 at 1:31
  • $\begingroup$ You are right. Now C# is read correctly but there are extra \" at the beginning and the end of my strings. $\endgroup$
    – Hamideh
    Commented Jun 27, 2016 at 15:18
-1
$\begingroup$

Try using eithertry or tryCatch:

See here http://stackoverflow.com/questions/13613270/how-to-fix-the-error-in-r-of-no-lines-available-in-input

$\endgroup$
1
  • $\begingroup$ I don't know how to integrate it with my code. $\endgroup$
    – Hamideh
    Commented Jun 24, 2016 at 13:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.