r - RStudio "Go to function definition" goes to copied source file instead of .GlobalEnv - Stack Overflow

I am using Rstudio (2024.12.1 Build 563 "Kousa Dogwood" Release (27771613, 2025-02-02) for wi

I am using Rstudio (2024.12.1 Build 563 "Kousa Dogwood" Release (27771613, 2025-02-02) for windows). If I source a file helper_functions.R using this code:

helper_function_path <- "/path_to/helper_functions.R"
source(helper_function_path)

and then highlight a function name and press F2, "the code is displayed in a special Source Viewer pane which is read-only" ():

However, if I then make a copy of helper_functions.R using this code:

dir_out <- "tmp"
if(!dir.exists(dir_out)) dir_out %>% dir.create(recursive = TRUE)
fn <- helper_function_path %>% basename()
fp <- fn %>% file.path(dir_out, .)
if(file.exists(fp)) file.remove(fp)
helper_function_path %>% file.copy(fp)

the next time I highlight a function name and press F2, RStudio opens (and allows me to edit) the copied file ./tmp/helper_functions.R, not the original file /path_to/helper_functions.R:

I have three questions:

  1. Is this behavior expected?
  2. Is there a way to copy helper_functions.R without causing F2 to open the copied file?
  3. Is there a way to cause F2 to open the original file?

Thanks!

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744375286a4571156.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信