Setting working directory to external volume and importing data from external hard drive

I posted my question here already, but was wondering if the community have an answer.

I have a volume is called BOB and a data text file at /Volumes/BOB/datafolder/data.txt. When I want to set the directory to the volume, it works.

    setwd("/Volumes/BOB/") # This works 

However, when I use list.files() it tells me character(0), but I can clearly see in my Finder that there are folders here. In addition the command below don't work as expected.

    setwd("/Volumes/BOB/datafolder/") # This reverts to $HOME or ~ and doesn't go to the folder... 

So whenever I try to point to a dataset on a volume, it tells me that

    Error in file(con, "r") : cannot open the connection
    In addition: Warning message:
    In file(con, "r") :
      cannot open file '/Volumes/BOB/datafolder/data.txt': Operation not permitted

I tried putting a subset of the data on the main drive of the computer and it worked. However, the data is very large and can't put the full dataset on my main drive. Would be awesome to be able to read the data directly from the external hard drive.

How could this be possible with RStudio?

Thanks a lot!

What are the file permissions on the datafolder folder and the data.txt file? Is it possible that you are running RStudio under an account that does not have access permissions to them?

The permission is this:

drwxrwxr-x   28 root   wheel   1.0K  9 Apr 17:17 . (folder)
-rw-r--r--@   1 USER  wheel   505B  9 Apr 17:17 data.txt (file)

The external hard drive was formatted to be USB External Physical Volume • Mac OS Extended (Journaled) on Mac. But again, the list.files()returns nothing. But the file is really there.

If you run in the RStudio console, does either the "user" or "effective_user" entry match "USER"? If not, are they in the "wheel" user group on your Mac?

Thanks for the help!

'user' and 'effective_user' are the same and they match echo $USER. Also, there is no 'wheel' user group. Actually, I just tried putting the data on another external volume and it worked. I really don't know why the other drive doesn't want to be recognized by RStudio...

OK, I might have solved it. We'll see how it going to work in the future. Basically, when trying the data on another hard drive, I noticed that macOS was asking me to grant access to RStudio the new hard drive.

It got me thinking, from the suggestion you made, that there was a problem with the privacy or accessibility of the drive. So I went in System Settings -> Privacy & Security -> RStudio. Then under Removable Volumes I switched it off (Restarted RStudio) and then on again (Restarted RStudio). Then I had access to the files!

Hopefully this was the fix. Although it's not clear to me why it was doing this thing...

1 Like

If the solution sticks, you might want to click the "checked box" icon under your answer to let the community know that the problem is solved.

Thanks a lot for your help!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.