What is the difference between list.files and dir?

vivek

I tried using both list.files and dir; both commands returned the same output. What is the key difference between these two commands and what's their usage context?

lmo

They are identical in the sense that they take the same arguments, these arguments have identical defaults, and they use the same .Internal function to execute.

As pointed out by @RichScriven in the comments, a compact and accurate test that they are the same can be run using identical:

identical(list.files, dir)
[1] TRUE

We can also take a look at their source code.

dir
function (path = ".", pattern = NULL, all.files = FALSE, full.names = FALSE, 
    recursive = FALSE, ignore.case = FALSE, include.dirs = FALSE, 
    no.. = FALSE) 
.Internal(list.files(path, pattern, all.files, full.names, recursive, 
    ignore.case, include.dirs, no..))
<bytecode: 0x000000000fe1c388>
<environment: namespace:base>

and

list.files
function (path = ".", pattern = NULL, all.files = FALSE, full.names = FALSE, 
    recursive = FALSE, ignore.case = FALSE, include.dirs = FALSE, 
    no.. = FALSE) 
.Internal(list.files(path, pattern, all.files, full.names, recursive, 
    ignore.case, include.dirs, no..))
<bytecode: 0x0000000008811280>
<environment: namespace:base>

Note that

.Internal(list.files(path, pattern, all.files, full.names, recursive, 
        ignore.case, include.dirs, no..))

is executed in both functions.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

difference between /dir and /dir/

What is the difference between "user.dir" and "."?

What's the difference between "dir" and "ls"?

What's the difference between hasattr() and 'attribute' in dir()?

What is the difference between min_file_process_interval and dag_dir_list_interval in Apache Airflow 1.9.0?

what is the difference between .so and .a files?

What is the difference between .tar files

Difference between print(dir()) and dir()

What is the difference between Files.list and Files.walkFileTree and Files.walk with maxdepth = 1?

What's the difference between list() and []

What is the difference between Set and List?

What is the difference between quote and list?

What is the difference between List and ArrayList?

What is the difference between [[]] and $ in list indexing?

What is the difference between @$_FILES and $_FILES in php?

What's the difference between console.dir and console.log?

what's the biggest difference between dir and __dict__ in python

what's the biggest difference between dir and __dict__ in python

What is the difference between mount -a and mount -o remount /dir?

What is the difference between a list of tuples and a list of objects?

What is the difference between list += str and list += str,

What is the difference between ('a * 'a) list and 'a * 'a list in ocaml?

What is the difference between list and list[:] in python?

What's the difference between List<Object> and List<?>

What is the difference between List<Object[]> and List<Object>?

What's the difference between list[::] and list?

Difference between CMAKE_CURRENT_SOURCE_DIR and CMAKE_CURRENT_LIST_DIR

Java dir/files list

Android - What is the difference between these three xml files?