To install a package in R call the install function in the prompt like this
install.packages("swirl", dependencies=TRUE)
Then when you have install swirl you can load in the library in your R file by using library()
library(swirl)
Now the library swirl has been loaded and you can now call the swirl functions
swirl()
Source: https://www.rdocumentation.org/packages/utils/versions/3.6.2/topics/install.packages