Skip to content

dir.exists returns FALSE on Symlink directory

6 messages · Ivan Krylov, Stephen H. Dawson, DSL, Serguei Sokol +1 more

#
I hope I'm not asking a stupid question... If I symlink a directory, is symlink considered as directory in R? If so, why `dir.exists` returns FALSE on directory?

I understand symlink is essentially a file, but functionally a symlink to directory is no different to the directory itself, but a directory is also essentially a file.

Is there any way that allow me to check if a symlink is linked to directory in base R, like `dir.exists(..., symlink_ok = TRUE)`?

Thanks,
Dipterix
#
? Mon, 26 Jun 2023 10:26:07 -0400
Dipterix Wang <dipterix.wang at gmail.com> ?????:
It seems to work, at least on GNU/Linux:

# (on this system, /var/lock is a symbolic link pointing to /run/lock/)
system('ls -l /var/lock')
# lrwxrwxrwx 1 root root <...> /var/lock -> /run/lock
dir.exists('/var/lock')
# [1] TRUE
Which operating system? Judging by your User-Agent, it must be some
version of macOS. Can you provide the output of `ls -l` on the symbolic
link?
#
It sounds like either R as a whole or the R session does not have 
permission to view the directory.


*Stephen Dawson, DSL*
/Executive Strategy Consultant/
Business & Technology
+1 (865) 804-3454
http://www.shdawson.com
On 6/26/23 11:07, Ivan Krylov wrote:
#
Le 26/06/2023 ? 16:26, Dipterix Wang a ?crit?:
Many think that there is no such thing as "stupid question". However, 
this one looks more appropriate for r-help list, does not it?
What about :

dir.exists(Sys.readlink("your_link"))

?

Best,
Serguei.

  
    
#
Le 26/06/2023 ? 17:17, Serguei Sokol a ?crit?:
Or even better:

file_test("-d", "your_real_dir_or_simlink_to_dir")

which returns TRUE for both a real dir and a simlink to a dir.

Best,
Serguei.

  
    
#
Thanks!

I think Sys.readlink resolved my issue. Indeed I found a permission issue. I will post my questions to r-help next time.

Best,
Dipterix