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?
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.
Comments