When using withr::with_libpaths a lot of related packages also get installed in the specified folder. If you just want to install the package in a specific folder use this command:
withr::with_libpaths
devtools::install(args = c('--library=path/to/directory'))