I've looked through many questions similar to this (see end of post), but I haven't found any solutions that actually accomplish what I need. I code on either Windows or Fedora depending on the project, and I code for people who use Windows and several Linux distributions.
Part of my job is making R scripts for people that automatically analyze data and create graphs. Most commonly, I'll just send them the script and it will generate the graph. This way, if the data changes or expands, I don't need to re-run the script for them (also, they can make changes as needed).
The problem is that I don't know how to get an R-script to find out where itself is located. It would be very convenient to just be able to create code that works as follows:
somewhere in the "load the script" process, you are passing the name and path of the R script. I'm suggesting to capture that information and then use a wrapper script to execute your main script.
the wrapper function that takes as an argument the path and fiile name of the script to execute
FILE <- "~/Desktop/myFolder/InHere/myScript.R"
at the start of your wrapper function, let the user click through to the file:
FILE <- file.choose()
DIR <- dirname(FILE)
and there you have your directory/folder and you can execute your script as normal passing
DIR as a parameter