How i Connect the data that's in my folder without writing the specific path like:"C:\\Users\\Dima\\Desktop\\NewData\\..."

I am writing a script that's Requires Data Which is in my computer folder.

But eventually this script will be used in another computer, by another person.

I can't tell him to change all the paths to the data in the script.

How i Connect the data that's in my folder without writing the specific path

Like:"C:\Users\Dima\Desktop\NewData\..."

Answers


The best way of making your code shareable depends upon your use case.

As Carl Witthoft pointed out, most code should be encapsulated in functions. These functions can then be packaged into packages and easily redistributed on other peoples's machines. Writing packages is easier than you think.

For one off analyses, scripts are appropriate. How you make them user-independent depends on who your users are. If your are sharing the script with colleagues, try to keep your data on a network drive, then the link to the data will be the same for everyone. If you are sharing your script with the world, then keep your data on the internet, and the link to the data will be a hyperlink, again, the same for everyone.

If you are sharing your script with a few people who don't have access to a common drive, and you can't put your data on the internet, then some directory manipulation is acceptable.

Change your working directory to the root of where your project files are.

setwd("c:/Users/Dima/My Project")

Then you can reference the location of the data using relative paths.

data_file <- "Data/My data file.csv"
my_data <- read.csv(data_file)

Assuming that you keep the directory structure within your project the same, then you only need to change the call to setwd on each machine.

Also note that the special location "~" refers to your user home directory. Try

normalizePath("~")

That way, if you keep your project in that location, you can avoid reference to "Dima" entirely.


Need Your Help

Service has leaked ServiceConnection that was originally bound here

android service broadcastreceiver intentservice

I am using a BraodCastReceiver that starts an IntentService. Everythings look working good, but I get this error which I don't know its source:

how do I attach a javascript SDK function for Facebook to a button?

javascript html facebook api

from the facebook docs it reads I have to use the following following function: