stagedtrees is an R package which includes several algorithms for learning the structure of staged trees and chain event graphs from data. Score-based and distance-based algorithms are implemented, as well as various functionalities to plot the models and perform inference. The capabilities of stagedtrees are illustrated using mainly two datasets both included in the package or bundled in R.