Q:

sorting files in R: How can I make the results consistent? 

When using list.files, I get different sorting results on different computers.   How can I make it so I always get the second behavior, which sorts padded numbers the way a human would? 
Computer 1 (Debian)
$ uname -a
Linux work 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt9-2 (2015-04-13) x86_64 GNU/Linux
$ touch 02 10 _2
$ R -e "list.files()"

R version 3.1.1 (2014-07-10) -- "Sock it to Me"
Copyright (C) 2014 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY. 
You are welcome to redistribute it under certain conditions. 
Type 'license()' or 'licence()' for distribution details. 

  Natural language support but running in an English locale

R is a collaborative project with many contributors. 
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications. 

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help. 
Type 'q()' to quit R.

> list.files()
[1] "02" "10" "_2"

Computer 2 (SUSE)
> uname -a
Linux efrc3 3.16.7-21-desktop #1 SMP PREEMPT Tue Apr 14 07:11:37 UTC 2015 (93c1539) x86_64 x86_64 x86_64 GNU/Linux
tug04419@efrc3:~/temp> touch 02 10 _2
tug04419@efrc3:~/temp> R -e "list.files()"
R version 3.1.1 (2014-07-10) -- "Sock it to Me"
Copyright (C) 2014 The R Foundation for Statistical Computing
Platform: x86_64-suse-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY. 
You are welcome to redistribute it under certain conditions. 
Type 'license()' or 'licence()' for distribution details. 

  Natural language support but running in an English locale

R is a collaborative project with many contributors. 
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications. 

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help. 
Type 'q()' to quit R.

> list.files()
[1] "_2" "02" "10"

A:

I've got a few different linux & OS X systems and some have various locale settings and others do or don't have ICU capabilities in R. To get consistency (I'll show two systems here) I had to disable locale-specific collation with Sys.setlocale("LC_COLLATE", "C"):
# osx01
Rscript -e 'system("touch 02 10 _2") ; list.files() ; Sys.setlocale("LC_COLLATE", "C") ; list.files()'
[1] "02" "10" "_2"
[1] "C"
[1] "02" "10" "_2"

# linux02
Rscript -e 'system("touch 02 10 _2") ; list.files() ; Sys.setlocale("LC_COLLATE", "C") ; list.files()'
[1] "_2" "02" "10"
[1] "C"
[1] "02" "10" "_2"

The '[1] "C"' in the output there is just something Sys.setlocale() spews and isn't a result of the list.files(). 
You can also set LC_COLLATE system-wide or in a shell script that calls Rscript or in .Renviron

