The goal of LegoR is to make it easy to get Lego-centric data into R.

Lego.com

The first set of functions provide a convenient way to scrape data from https://shop.lego.com/. These functions are based on the rvest package and depend on the structure of the site; site updates may break the functionality. All functions for lego.com start with the lego_ prefix.

The natural approach to gather data on all currently available lego sets is to get all sets by theme.

Each theme link leads to a page with one or more sets.

If the goal is to get the price and titles, we could stop here, but more set data is available on the set-specific page.

These sets are structured in order to provide easy pipe functionality:

Brickset

https://brickset.com/ contains data on historical lego sets as well as current sets. Unlike Lego.com, we can access Brickset data using an API (application programming interface). This does require registering for a brickset account and requesting an API key. All functions for the brickset.com data start with the brickset_ prefix.

brickset_setup() # guides you through the account setup process

Once you have your credentials, you can save them to your Rprofile using brickset_save_credentials(). This will also save the credentials as global variables.

brickset_save_credentials("your_username", "your_password", "your_api_key")

Then, you can access brickset’s data by authenticating. You may have to periodically reauthenticate depending on your internet configuration, but most functions should refresh the authentication automatically.

As with the Lego store, sets on brickset are organized by theme.

We can see what themes existed at the beginning…

Or the themes that have been around the longest…

Most of the functions described in the API documentation have been wrapped; the exception is functions which concern a user’s personal collection.