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?
When a package is installed globally, it's made available to all users that log into the system. Typically, that means Python and all packages will get installed to a directory under /usr/local/bin/ for a Unix-based system, or \Program Files\ for Windows.
A USPS parcel tracking number is a unique set of numbers assigned to your order. This USPS tracking number can be used to track your USPS package and receive real-time updates from USPS on your parcels.
R packages are installed in a directory called library. The R function . libPaths() can be used to get the path to the library.
Just run .libPaths()
and it will show you the filepath to your library
folder. Inside the library folder you can see all your packages.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With