[英]Finding location of the current file
My question is exactly similar to this question . 我的问题与这个问题完全相似。 I tried all the solutions listed there but they didn't work :( 我尝试了那里列出的所有解决方案,但是它们没有用:(
Only difference is that I am not sourcing other R files. 唯一的区别是我不采购其他R文件。 I am going to read csv files that are at the same location as the current R script. 我将读取与当前R脚本位于同一位置的csv文件。
I need this feature as that way I can transfer R file easily to other PCs/systems 我需要此功能,因为这样我就可以轻松地将R文件传输到其他PC /系统
I want that solution to work on Rstudio and command line and on Windows and Linux. 我希望该解决方案能在Rstudio和命令行以及Windows和Linux上运行。
I would like to offer a bounty of 50 credits 我想提供50个积分的赏金
How about adding this to your script? 如何将此添加到脚本中?
currentpath <- getwd()
Then you can read the csv file foo.csv
with 然后您可以使用以下命令读取csv文件foo.csv
read.csv(paste0(currentpath,'/','foo.csv'))
To make the code more platform independent you can explore the normalizePath
function. 为了使代码更独立于平台,您可以探索normalizePath
函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.