Path to access github file

The github site GitHub - fcas80/jt_files contains three files.
I can access uscities.csv with no problem, but why does the same path fail for censuspop.xlsx ?

df1 <- read.csv("")

df2 <- read_excel("")

also do not work.

What path do I need to access censuspop.xlsx ? Thank you.

If you check ?read.csv(), you will see the first argument is:

file the name of the file which the data are to be read from. Each row of the table appears as one line of the file. If it does not contain an absolute path, the file name is relative to the current working directory, getwd(). Tilde-expansion is performed where supported. This can be a compressed file (see file).

Alternatively, file can be a readable text-mode connection (which will be opened for reading if necessary, and if so closed (and hence destroyed) at the end of the function call). (If stdin() is used, the prompts for lines may be somewhat confusing. Terminate input with a blank line or an EOF signal, Ctrl-D on Unix and Ctrl-Z on Windows. Any pushback on stdin() will be cleared before return.)

file can also be a complete URL. (For the supported URL schemes, see the ‘URLs’ section of the help for url.)

However, read_excel() did not implement this, it expects path to be a string giving the path to a local file. If you look at the source code, you will notice that this is explicitly enforced: the first line of read_excel() is path <- check_file(path) which fails if path is not a string.

So you can read the file with:

              "censuspop.xlsx", mode = "wb")
df2 <- readxl::read_excel("censuspop.xlsx")

Note: if you don't want to fill your current working directory, you can save the file as a temporary file:

temp_path <- tempfile()
              temp_path , mode = "wb")
df2 <- readxl::read_excel(temp_path )
1 Like

Alexis, thank you. It looks like I was missing mode = "wb" for a binary file.

1 Like

Yep, that's a common "gotcha" for download.file(), I had to learn it the hard way : )

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.