Skip to content
This repository has been archived by the owner on Mar 9, 2022. It is now read-only.

Sorting differs on deployment (maybe OS/Locale issue) #10

Open
ghost opened this issue Jan 31, 2022 · 0 comments
Open

Sorting differs on deployment (maybe OS/Locale issue) #10

ghost opened this issue Jan 31, 2022 · 0 comments

Comments

@ghost
Copy link

ghost commented Jan 31, 2022

Hi,

Thanks for a great package! Natural sort is not something that is implemented elsewhere in a good manner :)

I use the function naturalsort to sort file names just like windows explorer, which works great locally.

But when I use it in my production environment deployed with Docker on Google Cloud Run, the sorting changes. I don't know if this is due to changes in locale(I am fra Denmark) or it is due to OS differences between my windows PC and the Docker/Google Cloud Run deployment.

I have created a example ready to be run in R:

######## Code start ###########
require(plumber)
require(naturalsort) #for name sorting

#* Retrieve sorted string list
#* @get /sortstrings
#* @param nothing
function(nothing) {
  
  print(nothing)
  
  test <- c("0.jpg", "file (4_5_1).jpeg", "1 tall thin image.jpeg",
            "8.jpeg", "8.jpg", "file (2.1.2).jpeg", "file (0).jpeg", "3.jpeg",
            "file (1).jpeg", "file (2.1.1).jpeg", "file (0) (3).jpeg", "file (2).jpeg",
            "file (2.1).jpeg", "file (4_5).jpeg", "file (4).jpeg", "file (39).jpeg")
  
  print("Direct sort")
  print(naturalsort(text = test))
  
  sorted_strings <- naturalsort(text = test)
  
  return(sorted_strings) 
}
######## Code end ###########

I would expect it to sort the file names like below, which it does locally both when run directly in the script and also when doing it through plumber RUN API.

sort

But instead it sorts it like this:

c("0.jpg",
"1 tall thin image.jpeg",
"3.jpeg",
"8.jpeg",
"8.jpg",
"file (0) (3).jpeg",
"file (0).jpeg",
"file (1).jpeg",
"file (2.1.1).jpeg",
"file (2.1.2).jpeg",
"file (2.1).jpeg",
"file (2).jpeg",
"file (4_5_1).jpeg",
"file (4_5).jpeg",
"file (4).jpeg",
"file (39).jpeg")

Hope you can help :)

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

No branches or pull requests

0 participants