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:
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.
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.