For people that are still trying to figure this out, Lmod can be used from within an R code to load additional modules without any issue:
You for example can use
source("/usr/share/lmod/lmod/init/r")
and then you have a new R function called module()
to use like you would on the CLI.
module("list")
module("avail")
module("purge")
module("load Software/x.y.z")