Michael Williams
Michael Williams

Reputation: 1195

Knitr chunk is importing a subset of the records from *.csv as same code in R

Rstudio version 0.96.331 and knitr version 0.8

I thought my problem had been solved with update of RStudio and libraries... however:

The following run in R gives me 940 unique Table.ID values. Run in a knitr chunk I get 228 unique values and the following warning:

"invalid input found on input connection 'http://www2.census.gov/acs2010_5yr/summaryfile/Sequence_Number_and_Table_Number_Lookup.txt'

I don't understand why the distinction exists between the two methods.

Sequence <- read.csv("http://www2.census.gov/acs2010_5yr/summaryfile/Sequence_Number_and_Table_Number_Lookup.txt",
                   stringsAsFactors=FALSE)
unique(Sequence$Table.ID)

enter image description here enter image description here

Upvotes: 4

Views: 584

Answers (1)

Maiasaura
Maiasaura

Reputation: 32996

Works fine on Rstudio version 0.96.331 and knitr version 0.8

My .Rmd file:

        knitr test for length
        ========================================================
        This should successfully return a length of 940

    ```{r}
    Sequence <- read.csv("http://www2.census.gov/acs2010_5yr/summaryfile/Sequence_Number_and_Table_Number_Lookup.txt", 
fileEncoding = "iso8859-8", stringsAsFactors = FALSE)
    length(unique(Sequence$Table.ID))
    ```

Resulting in this:

enter image description here

Upvotes: 5

Related Questions