Well, about the excerpt:
"As the code I’m making will be sent to someone else, I can’t put an absolute path, and I’m having trouble applying the function to a relative path."
We can know what to put in the way (path
) through the use of two functions:
getwd()
and
setwd()
getwd
is similar to the command pwd
in the Linux system terminal and, returns the path of the current directory, in which you are. Exemplifying:
getwd()
returns something like:
/home/seunome/Documents/meu.xlsx
setwd
is similar to the command cd
on the Linux terminal and, changes the current directory to what you need. Let’s assume that the file you want to import is in the folder Downloads
, you can do this:
setwd(dir = "/home/seunome/Downloads")
And change the working directory to the folder Downloads
:
Now, you can import your file from this folder with this command:
library(rio)
lista_1 <- import_list(file = "home/seunome/Downloads/meuarquivo.xlsx")
Where "home/seunome/Downloads/meuarquivo.xlsx"
is the path of your Excel file.
This package (rio
) is very easy to understand, and the advantage of learning it compared to what was mentioned in the previous answers is to try to standardize the import of data in many other formats, not only in Excel, but also csv
for example.
More details about this package you can find here.
Thank you very much for the answer, I see that could solve my problem in several ways. In the end I managed to solve it using the read.csv2 function. The code looks like this: setwd("C:/Users/PEDRO/PUC/TPE/Job 2/G2") file = "data/Enterprise.csv" base = read.csv2(file, Sep = ";") The problem was in setting the file address.
– user6894
If you want you can accept the @mechanical_fan reply, or add your own comment and accept it. Accepting answers that help you is part of the OS etiquette, and it’s wrong to accept answers from yourself.
– fridaymeetssunday