0

I have poorly-formatted CSV files imported as large list elements then rbind into a dataframe. Trying to inspect the elements of this large list in RStudio 1.0.143 (Windows 10 Pro), the following commands all result in 200 lines output to Console:

head(ldf[1],10)
head(ldf[1])
head(ldf[1],10L)
head(ldf[2],10L)
head(ldf[2],9)
head(ldf[2],n = 9L)

At the end of this output will be a statement like:

[ reached getOption("max.print") -- omitted 5944 rows ]

Why is the integer argument being ignored? Does it matter that I have loaded the tidyr package?

sebastian-c
  • 14,667
  • 3
  • 43
  • 91
DBinJP
  • 247
  • 3
  • 13
  • 3
    try `head(ldf[[1]],10)` – baptiste Sep 20 '17 at 08:41
  • That worked, thank you. Where do I go to learn about the difference between list[index] and list[[index]]? I've seen so many intro to R pages and somehow did not learn this distinction. After a bit of searching, I have found a page here discussing it: https://stackoverflow.com/questions/22431261/understanding-list-indexing-and-bracket-conventions-in-r – DBinJP Sep 20 '17 at 08:55
  • To quote a sentence from the page hadley linked in the SO question you linked: `Using [ will always return a list; [[ and $, as described below, let you pull out the components of the list.` – LAP Sep 20 '17 at 09:16
  • Have a look in the [Introduction to R](https://cran.r-project.org/manuals.html) manual. In section 6 there is an explanation. – Bhas Sep 20 '17 at 09:17

1 Answers1

0

You must be careful when indexing (aka "subsetting") in R. Having loaded tidyr apparently does not matter; apparently you were calling the entire list instead of the first element of the list, which is why the argument to restrict the output was being ignored.

See the official documentation on indexing, Hadley Wickham's discussion on what he calls subsetting, and a previous StackOverflow post discussing indexing.

It would also be good to read about lists and data frames in An Introduction to R Section 6.1: Lists as Bhas suggests.

DBinJP
  • 247
  • 3
  • 13