I am building an R package (let's call it "pkg"), and would like to write a function that downloads a file from the internet and saves it in the "inst/extdata" directory in my package's directory.
download_file <- function(link) {
path <- ... # path to where "pkg" is stored
# something along the lines of ....../pkg
download.file(link, paste(path, "inst/extdata", "newfile", sep = ""))
}
Could you please help me get the "path"? While developing the package, I can just do "getwd()" -- however, when a user calls my package, her working directory might not be the pkg directory. In which case, how do I get the path to my package's directory?
find.package
. - Andrey Shabalinsystem.file('extdata', package = 'pkg')
but you should probably usetempfile
/tempdir
or have the user specify a location. you also will not see the/inst
folder underlist.files(system.file(package = 'pkg'))
- rawr