What is the difference between list.files and dir?

I tried to use both list.files, and dir; both teams returned the same output. What is the key difference between the two teams and their context of use?

+4
source share
1 answer

They are identical in the sense that they accept the same arguments, these arguments have the same default values, and they use the same function .Internalto execute.

As pointed out in the comments by @RichScriven in the comments, a compact and accurate test that they are the same can be run with 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..))

performed in both functions.

+5

Source: https://habr.com/ru/post/1672952/


All Articles