Question: I'm trying to load the table of Supreme Court Justices into R from the following URL.
<https://en.wikipedia.org/wiki/List_of_Justices_of_the_Supreme_Court_of_the_United_States>

I'm using the following code:

```
scotusURL <- "https://en.wikipedia.org/wiki/List_of_Justices_of_the_Supreme_Court_of_the_United_States"
scotusData <- getURL(scotusURL, ssl.verifypeer = FALSE)
scotusDoc <- htmlParse(scotusData)
scotusData <- scotusDoc['//table[@class="wikitable"]']
scotusTable <- readHTMLTable(scotusData[[1]], stringsAsFactors = FALSE)

```

R returns scotusTable as NULL. The goal here is to get a data.frame in R that I can use to make a ggplot of SCOTUS justice tenure on the Court. I previously had the script working to make an awesome plot, however after the recent decisions something changed on the page and now the script will not function. I went through the HTML on wikipedia to try to find any changes, however I'm not a webdev so anything that would break my script isn't immediately apparent.

Additionally, is there a method in R that would allow me to cache the data from this page so I'm not constantly referencing the URL? That would seem to be the ideal way to avoid this issue in the future.
Appreciate the help.

As an aside, SCOTUS in an on-going hobby/side-project of mine so if there's some other data source out there that's better than wikipedia, I'm all ears. 

Edit: Sorry I should have listed my dependencies. I'm using the XML, plyr, RCurl, data.table, and ggplot2 libraries.

Answer: 
I would remove all the `<span style="display:none">` nodes and read the table from scotusDoc instead of trying to select a table class value that has changed.

```
scotusDoc <- htmlParse(scotusData, encoding="UTF-8")
xpathSApply(scotusDoc, "//span[@style='display:none']", removeNodes)
x <- readHTMLTable(scotusDoc, which=2,stringsAsFactors=FALSE)

head(x)
  #           Judge State Born/Died         Active service Chief Justice Retirement Appointed by Reason for\ntermination
1 1       John Jay†    NY 1745–1829   1789–1795(5–6 years)     1789–1795          —   Washington             Resignation
2 2   John Rutledge    SC 1739–1800   1789–1791(1–2 years)             —          —   Washington        Resignation[n 1]
3 3 William Cushing    MA 1732–1810 1789–1810(20–21 years)             —          —   Washington                   Death
4 4    James Wilson    PA 1742–1798   1789–1798(8–9 years)             —          —   Washington                   Death
5 5 John Blair, Jr.    VA 1732–1800   1789–1795(5–6 years)             —          —   Washington             Resignation
6 6   James Iredell    NC 1751–1799   1790–1799(8–9 years)             —          —   Washington                   Death

```

And here are table classes, so the second table is now a "wikitable sortable"

```
xpathSApply(scotusDoc, "//table", xmlGetAttr, "class")
[1] "wikitable"                                         "wikitable sortable"                               
[3] "navbox"                                            "nowraplinks collapsible autocollapse navbox-inner"
[5] "navbox"                                            "nowraplinks collapsible collapsed navbox-inner

```
For some reason the googlesheets dependency wasn't working, so I pulled it through google anyway. 

I ran:

```
=importhtml("https://en.wikipedia.org/wiki/List_of_Justices_of_the_Supreme_Court_of_the_United_States", "table", 2)

```

and then downloaded the file as a .csv

Don't know why I didn't think of that before. I'll have to re-write my string scripts to clean it up but this ended up being the best way to 1) fix the first problem I had and 2) download a file so that I don't have to keep referencing a URL.

Thanks for the help.