From f7f1ac2f1093c2c1af9dfb7b872444a651682508 Mon Sep 17 00:00:00 2001 From: Bruno Rodrigues Date: Fri, 27 Sep 2024 21:39:00 +0200 Subject: [PATCH] better test for existence of .Rprofile --- R/rix_init.R | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/R/rix_init.R b/R/rix_init.R index 99c107c0..5ff0f3cb 100644 --- a/R/rix_init.R +++ b/R/rix_init.R @@ -165,7 +165,12 @@ rix_init <- function(project_path, # signal message if not quiet message_r_session_nix_rstudio(is_nix_r, is_rstudio, message_type) - rprofile_exists <- `!=`(file.size(rprofile_file), 0) + # Test for existence and size instead of only existence, + # as an active file connection makes the file exist, but is empty + # Consider empty files as not existing to avoid not writing + # .Rprofile + rprofile_exists <- (file.exists(rprofile_file) & + `!=`(file.size(rprofile_file), 0)) timestamp <- format(Sys.time(), "%Y-%m-%dT%H:%M:%S%z") rprofile_backup <- paste0(rprofile_file, "_backup_", timestamp) @@ -222,7 +227,6 @@ rix_init <- function(project_path, } }, append = { - #writeLines(paste0(rprofile_text, "\n"), rprofile_con, mode = "a+") write_rprofile(rprofile_text, rprofile_file = rprofile_file, "a+") message_rprofile( action_string = "Appended", project_path = project_path