Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

does not seem to be case sensative #98

Open
zaslove opened this issue Oct 2, 2023 · 12 comments
Open

does not seem to be case sensative #98

zaslove opened this issue Oct 2, 2023 · 12 comments

Comments

@zaslove
Copy link

zaslove commented Oct 2, 2023

Hallo,
I am not sure if this is a bug or something that is done on purpose. The file path does not appear to be case sensative. For example, both of these work. The file path on the one is without a capital f for file and for the second one there is a capital F for file.

df1 <- readRDS(here("final_data/xxx.RDS") )

df2 <- readRDS(here("Final_data/xxx.RDS") )

best,
Andrej

@krlmlr
Copy link
Member

krlmlr commented Oct 2, 2023

Thanks. The paths are different, but perhaps your file system is case-insensitive?

@zaslove
Copy link
Author

zaslove commented Oct 2, 2023

is there a way to make them case sensitive ...

@zaslove
Copy link
Author

zaslove commented Oct 2, 2023

thus the case sensitivity is not something that the here function catches?

@krlmlr
Copy link
Member

krlmlr commented Oct 2, 2023

A small example:

upper <- here::here("DESCRIPTION")
upper
#> [1] "/Users/kirill/git/R/fledge/DESCRIPTION"
lower <- here::here("description")
lower
#> [1] "/Users/kirill/git/R/fledge/description"

# Different paths
identical(upper, lower)
#> [1] FALSE

# Same canonical path
identical(fs::path_real(upper), fs::path_real(lower))
#> [1] TRUE
fs::path_real(lower)
#> /Users/kirill/git/R/fledge/DESCRIPTION

# Same file
identical(readLines(upper), readLines(lower))
#> [1] TRUE

Created on 2023-10-02 with reprex v2.0.2

The paths are different, but they point to the same file. I'm on macOS, the behavior will be the same on Windows, but most likely different on Linux. Are you looking for the functionality that fs::path_real() provides?

@zaslove
Copy link
Author

zaslove commented Oct 2, 2023

Hallo,
Thanks. I was just using the here function to import a data file, as I normally do. I miss typed the file name, with a lower case and I was still able to get the same file. I was surprised that it worked.

In other words, my file with my data file stays the same but I am able to access it with a upper and lower case using the here function from my script.

The file with my data is the following: final_data

I can access the same data file with the two scripts below.

df1 <- readRDS(here("final_data/xxx.RDS") )

df2 <- readRDS(here("Final_data/xxx.RDS") )

I hope this makes sense ...

@krlmlr
Copy link
Member

krlmlr commented Oct 2, 2023

I think we're almost on the same page here. What happens if you ask fs::path_real(here("final_data/xxx.RDS")) ?

@zaslove
Copy link
Author

zaslove commented Oct 2, 2023

Yes, so if I do that then I get the data. Sorry I changed the file names but the concept works the same. The data file can be upper or lower case and I get the same data file.

If I do this, then I get the data:

fs::path_real(here("data/poppa2.rds"))
C:/Users/zaslo/Main_Documents_Folder/RESEARCH/CURRENT_RESEARCH/poppa_democracy_paper/data/poppa2.RDS

Here I get the same data. The fs::path_real is upper case but the path file is lower.

fs::path_real(here("Data/poppa2.rds"))
C:/Users/zaslo/Main_Documents_Folder/RESEARCH/CURRENT_RESEARCH/poppa_democracy_paper/data/poppa2.RDS

@zaslove
Copy link
Author

zaslove commented Oct 2, 2023

so what does this all mean :-)

@krlmlr
Copy link
Member

krlmlr commented Oct 2, 2023

Sorry, I don't understand the question.

@zaslove
Copy link
Author

zaslove commented Oct 2, 2023

oh sorry. I was just wondering where this leaves the discussion. In the end, the path is not case sensitive but it accesses the same file?

@krlmlr
Copy link
Member

krlmlr commented Oct 2, 2023

  • The path is a string, strings are case-sensitive. This means "a" != "A"
  • Your file system is case-insensitive. Two different paths can point to the same file
  • You can get a canonical path with fs::path_real(). Two different canonical paths point to different files

@zaslove
Copy link
Author

zaslove commented Oct 3, 2023

Many thanks!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants