0

I'm providing a .zip with a .R file and a .xlsx file to some people

I need to make a code that can read this .xlsx file in any directory of any pc.

But as the directories vary from computer to computer, I couldn't find a solution.

IMPORTANT: I'm not using Rstudio for read this .R, so i just can use base functions

Using R - How do I search for a file/folder on all drives (hard drives as well as USB drives) This question don't solve my problem..

Bryan Souza
  • 497
  • 2
  • 10

1 Answers1

0

Take a look at the here package. When you load the library (library("here")) it sets "base" working directory and then you can use the package to construct relative file paths given that location. For example, if inside your .zip file you have an R script (e.g., My Data Analysis.R) that analyzes data that is kept within a folder called data you could read it in using, for example, read.csv(here("data", "my_csv_file.csv")) and it will construct the full appropriate file path no matter what computer it is on. Of course the file structure of the program needs to stay the same across programs.

Brigadeiro
  • 2,649
  • 13
  • 30