I know that I can find file name from full file path in R, but is there a way to define the path to the file just from the file name? Think about such scenario: you store the data file in the cloud (e.g. Dropbox) so the path for this file is slightly different at your home: read.table('path/user1/data.dat')
and work: read.table('path/user2/data.dat')
. Therefore, every time you want to read.table()
you have to change one element of the path to match either you work or home path (on Mac OS X it's specifically the User
part of the path that you need to change). I was wondering whether it's possible to make R to automatically detect such change in the path (e.g. different User
) or detect the path to the file just from the name of this file.
I did read about this and tried it out yesterday. The problem is that when I add a hyperlink to an image file instead of an image file as a link, the image won't get displayed in my Excel sheet. I need to be able to view the images in my sheet and print them. – Port Islander 2009 Jun 25 '13 at 8:31.
1 Answer
You can access the environment variables with Sys.getenv()
.
Here is a short extract from the results on my machine:
You can extract individual elements by including the name of that element in the call:
![Data variable rip without image path software Data variable rip without image path software](http://scraping.pro/wp-content/uploads/PDFDataExtraction-uipath-image04.png)
If you can identify in these variables exactly what it is you need, you can then construct your file path using file.path
For more information on the environment variables, and some system-specific exceptions, see ?Sys.getenv