在 R Studio 中自动查找当前 R 项目的路径 [英] Automatically finding the path of current R project in R Studio

查看:40
本文介绍了在 R Studio 中自动查找当前 R 项目的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我在以下目录 /home/user/workarea/project1 中打开了一个 R 项目.现在我在下面有一个嵌套的目录结构,我正在编写一个函数,该函数应该从这个项目内的任何地方执行日志记录,我希望这个函数写入位于 /home/user/workarea/目录中的文件项目 1/日志.我计划将文件路径作为参数传递给这个函数.现在我知道这个文件将始终位于项目主目录中的/log 目录下——但是我如何自动找出哪个是我的项目目录,这样我就不会总是用 ...我不想硬编码我的本地路径 /home/user/workare/project1,但能够在我克隆我的项目的任何地方检测到这一点.

Say I have an R project opened at the following directory /home/user/workarea/project1. Now I have a nested directory structure underneath and I am writing a function that is supposed to perform logging from anywhere inside this project and I want this function to write into files that are located at the directory /home/user/workarea/project1/log. I plan to pass the file path as an argument to this function. Now I know that this file will always be located under the /log directory in the project's main directory - but how do I automatically find out which is my project directory, so that I don't always specify relative paths with ... I wouldn't want to hard-code my local path /home/user/workare/project1, but be able to detect this wherever I clone my project.

推荐答案

这听起来像 rprojroot 包将提供您正在寻找的内容——特别是 find_rstudio_root_file() 函数应该提供你需要的东西.

It sounds like the rprojroot package will provide what you're looking for -- in particular, the find_rstudio_root_file() function should provide what you need.

这篇关于在 R Studio 中自动查找当前 R 项目的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆