0

I have been interested in studying R programming language recently and I came through this line of code which I am not understanding.

rugbyData <- rugbyHTMLData %>% html_nodes("table.wikitable") %>% .[[3]] %>% html_table

What does %>% means?

1 Answers1

0

In R, %>% is the pipe operator.

It enables you to chain operations in a data pipeline, as the output of every step becomes the input of the next step.

Without it the code would look like this:

rugbyData <- rugbyHTMLData
extracted_nodes <- html_nodes(rugbyData, "table.wikitable")
selected_node <- extracted_nodes[[3]]
final_result <- html_table(selected_node)

...code that creates 3 useless variables

Note the "." that is a placeholder to say "the piped object goes here".

It's provide by the magrittr package →Reference

NB: why magrittr ? → "Ceci n'est pas une pipe / This is not a pipe"

Cylldby
  • 1,783
  • 1
  • 4
  • 17
  • Thank you so much for the code. Can you please comment in each line so that I can understand what it does? Because I am still a beginner in R. – Brams Abe Abey Apr 14 '21 at 08:34
  • It is actually quite difficult given the lack of context, but here is what I can figure out: if I'm correct you are using the `rvest` package to scrape a web page (I'm guessing a wikipedia page about Rugby, probably IRB rankings or World Cup winners) and extracting a table from there.. I can only suggest you to look the documentation of each function used here, particularly the inputs and outputs – Cylldby Apr 14 '21 at 14:53