Skip to content

Commit

Permalink
Merge pull request #338 from ropensci/fix_rix_init
Browse files Browse the repository at this point in the history
-  `rix_init()` & rix(): fixed a bug that resulted in empty `.Rprofile` files (fixed in `rix_init()`)
  • Loading branch information
philipp-baumann authored Sep 26, 2024
2 parents 8522ab7 + 928e786 commit 2189ada
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# rix 0.12.2 (2024-09-25)

# Chores
## Chores

- Update the url in the hex logo
- Update shipped `inst/extdata/default.nix` with this patch release of {rix}
Expand Down
20 changes: 11 additions & 9 deletions R/rix_init.R
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,14 @@ rix_init <- function(project_path,
rprofile_quoted <- nix_rprofile()
rprofile_deparsed <- deparse_chr1(expr = rprofile_quoted, collapse = "\n")
rprofile_file <- file.path(project_path, ".Rprofile")
rprofile_con <- file(rprofile_file, open = "wb", encoding = "native.enc")

rprofile_text <- get_rprofile_text(rprofile_deparsed)
on.exit(close(rprofile_con))
on.exit(close(file(rprofile_file)), add = TRUE)
write_rprofile <- function(rprofile_text, rprofile_file) {
writeLines(enc2utf8(rprofile_text), rprofile_con, useBytes = TRUE)
writeLines(
text = enc2utf8(rprofile_text),
con = file(rprofile_file)
)
}

is_nix_r <- is_nix_r_session()
Expand All @@ -167,7 +169,7 @@ rix_init <- function(project_path,
)
}
} else {
write_rprofile(rprofile_text, rprofile_file = rprofile_con)
write_rprofile(rprofile_text, rprofile_file)
if (isFALSE(is_quiet)) {
message_rprofile(action_string = "Added", project_path = project_path)
}
Expand All @@ -177,7 +179,7 @@ rix_init <- function(project_path,
create_backup = {
if (isTRUE(rprofile_exists)) {
file.copy(from = rprofile_file, to = rprofile_backup)
write_rprofile(rprofile_text, rprofile_file = rprofile_con)
write_rprofile(rprofile_text, rprofile_file)
if (isFALSE(is_quiet)) {
cat(
"\n==> Backed up existing `.Rprofile` in file:\n", rprofile_backup,
Expand All @@ -191,13 +193,13 @@ rix_init <- function(project_path,

if (message_type == "verbose") {
cat("\n* Current lines of local `.Rprofile` are\n:")
cat(readLines(con = rprofile_con), sep = "\n")
cat(readLines(con = file(rprofile_file), sep = "\n"))
}
set_message_session_PATH(message_type = message_type)
}
},
overwrite = {
write_rprofile(rprofile_text, rprofile_file = rprofile_con)
write_rprofile(rprofile_text, rprofile_file)
if (isTRUE(rprofile_exists)) {
message_rprofile(
action_string = "Overwrote", project_path = project_path
Expand All @@ -209,7 +211,7 @@ rix_init <- function(project_path,
}
},
append = {
cat(paste0(rprofile_text, "\n"), file = rprofile_con, append = TRUE)
cat(paste0(rprofile_text, "\n"), file = rprofile_file, append = TRUE)
message_rprofile(
action_string = "Appended", project_path = project_path
)
Expand All @@ -218,7 +220,7 @@ rix_init <- function(project_path,

if (message_type == "verbose") {
cat("\n\n* Current lines of local `.Rprofile` are:\n\n")
cat(readLines(con = rprofile_action), sep = "\n")
cat(readLines(con = file(rprofile_file)), sep = "\n")
}
}

Expand Down

0 comments on commit 2189ada

Please sign in to comment.