file.symlink reprex

i'm looking for a reprex on how to use file.symlink
The example in the help file is, typically, less than helpful.

I did see this post, but i don't know what 'data' is.

My end goal: Move a file from the current directory, to another directory where the path to the location is longer than R will allow (like.. 230 character is the limit for file.copy or something).
The following code was working until this morning, but no longer does, and I don't know enough about why it's not working now to debug (no error message)

SOW_DIRECTORY <- "really really really long file path"
# \ -- create the symbolic link to that path
create.symlink <- paste0("subst x: ",'"',SOW_DIRECTORY, '"') 
system(create.symlink)
file.copy(from = filename, to   = file.path("x://", filename))
# \-- remove the copy in the working directory
file.remove(filename)
# \-- remove the symbolic link
system("subst x: /D")

so i was going to try to use file.symlink instead of subst .... but am not sure how to actually implement it.

In the example I gave, data is the name of a new "subfolder" in your current working directory that is actually the folder with the really long file path. So when I do this:

file.symlink('/some/common/data/location/', 'data')

I get what looks like a new subfolder in my project called 'data', but if I open that folder I see the contents of '/some/common/data/location/'. We are just giving a name to the link. R itself won't know the difference, it will also see it as a subfolder of your current directory.

A couple other points: The symlink can be versioned with Git, but only the link will be preserved, not the contents of the folder. If you delete the 'data' folder, on many systems it will only delete the link, not the folder it is connected to but you should test this to make sure it is true on your OS.

Edited to clarify that last point, I'm accustomed to Unix-based systems.

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

Not working smoothly unfortunately.

I'm getting this error: cannot symlink 'super long path' to 'shorter path', reason 'A required privilege is not held by the client'

When indeed i do have read/write privileges to both folders. Any thoughts?

Ironically, the older method i was using in the original post is back to working. Box was acting up that day, so perhaps that was the glitch.

so if i want to export a file to that external folder with a really long path, i only have to write something like
write.csv("data/filename.csv")
Excellent, that make sense.

This is going to be an OS issue, rather than n R issue per se.

Perhaps if you login 'as admin' you could access that level of priviledge ?