How to find location of package?

10,916

Just run .libPaths() and it will show you the filepath to your library folder. Inside the library folder you can see all your packages.

Share:
10,916
Karan Tibrewal
Author by

Karan Tibrewal

Updated on June 20, 2022

Comments

  • Karan Tibrewal
    Karan Tibrewal almost 2 years

    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?