Skip to content

Commit

Permalink
Implement "append" option
Browse files Browse the repository at this point in the history
  • Loading branch information
philipp-baumann committed Jan 16, 2024
1 parent 1aa7832 commit ed0b628
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 26 deletions.
28 changes: 15 additions & 13 deletions R/find_rev.R
Original file line number Diff line number Diff line change
Expand Up @@ -844,10 +844,6 @@ init <- function(project_path = ".",
"\n* Keep existing `.Rprofile`. in `project_path`:\n",
paste0(project_path, "/"), "\n"
)
if (message_type == "verbose") {
cat("\n* Current lines of local `.Rprofile` are:\n\n")
cat(readLines(con = file(rprofile_file)), sep = "\n")
}
} else {
write_rprofile(rprofile_text, rprofile_file)
message_rprofile(action_string = "Added", project_path = project_path)
Expand All @@ -856,10 +852,6 @@ init <- function(project_path = ".",
},
create_backup = {
if (isTRUE(rprofile_exists)) {
if (message_type == "verbose") {
cat("\n* Current lines of local `.Rprofile` are\n:")
cat(readLines(con = file(rprofile_file)), sep = "\n")
}
file.copy(from = rprofile_file, to = rprofile_backup)
cat(
"\n==> Backed up existing `.Rprofile` in file:\n", rprofile_backup,
Expand All @@ -870,6 +862,10 @@ init <- function(project_path = ".",
action_string = "Overwrote",
project_path = project_path
)
if (message_type == "verbose") {
cat("\n* Current lines of local `.Rprofile` are\n:")
cat(readLines(con = file(rprofile_file)), sep = "\n")
}
set_message_session_PATH(message_type = message_type)
}
},
Expand All @@ -884,12 +880,19 @@ init <- function(project_path = ".",
action_string = "Added", project_path = project_path
)
}
if (message_type == "verbose") {
cat("\n* Current lines of local `.Rprofile` are:\n\n")
cat(readLines(con = file(rprofile_file)), sep = "\n")
}
},
append = {
cat(paste0(rprofile_text, "\n"), file = rprofile_file, append = TRUE)
message_rprofile(
action_string = "Appended", project_path = project_path
)
}
)

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

on.exit(close(file(rprofile_file)))
}
Expand All @@ -910,7 +913,6 @@ get_rprofile_text <- function(rprofile_deparsed) {
)
}


#' @noRd
message_rprofile <- function(action_string = "Added",
project_path = ".") {
Expand Down
28 changes: 15 additions & 13 deletions dev/build_envs.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -943,10 +943,6 @@ init <- function(project_path = ".",
"\n* Keep existing `.Rprofile`. in `project_path`:\n",
paste0(project_path, "/"), "\n"
)
if (message_type == "verbose") {
cat("\n* Current lines of local `.Rprofile` are:\n\n")
cat(readLines(con = file(rprofile_file)), sep = "\n")
}
} else {
write_rprofile(rprofile_text, rprofile_file)
message_rprofile(action_string = "Added", project_path = project_path)
Expand All @@ -955,10 +951,6 @@ init <- function(project_path = ".",
},
create_backup = {
if (isTRUE(rprofile_exists)) {
if (message_type == "verbose") {
cat("\n* Current lines of local `.Rprofile` are\n:")
cat(readLines(con = file(rprofile_file)), sep = "\n")
}
file.copy(from = rprofile_file, to = rprofile_backup)
cat(
"\n==> Backed up existing `.Rprofile` in file:\n", rprofile_backup,
Expand All @@ -969,6 +961,10 @@ init <- function(project_path = ".",
action_string = "Overwrote",
project_path = project_path
)
if (message_type == "verbose") {
cat("\n* Current lines of local `.Rprofile` are\n:")
cat(readLines(con = file(rprofile_file)), sep = "\n")
}
set_message_session_PATH(message_type = message_type)
}
},
Expand All @@ -983,12 +979,19 @@ init <- function(project_path = ".",
action_string = "Added", project_path = project_path
)
}
if (message_type == "verbose") {
cat("\n* Current lines of local `.Rprofile` are:\n\n")
cat(readLines(con = file(rprofile_file)), sep = "\n")
}
},
append = {
cat(paste0(rprofile_text, "\n"), file = rprofile_file, append = TRUE)
message_rprofile(
action_string = "Appended", project_path = project_path
)
}
)
if (message_type == "verbose") {
cat("\n* Current lines of local `.Rprofile` are:\n\n")
cat(readLines(con = file(rprofile_file)), sep = "\n")
}
on.exit(close(file(rprofile_file)))
}
Expand All @@ -1009,7 +1012,6 @@ get_rprofile_text <- function(rprofile_deparsed) {
)
}
#' @noRd
message_rprofile <- function(action_string = "Added",
project_path = ".") {
Expand Down

0 comments on commit ed0b628

Please sign in to comment.