From f159ad9f44a890b486cc779ecf4828382645a6b0 Mon Sep 17 00:00:00 2001 From: Jake Tufts Date: Fri, 20 Sep 2024 13:25:25 +0100 Subject: [PATCH] Improve .Rprofile order, comments and msg in create_project() --- R/create_project.R | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/R/create_project.R b/R/create_project.R index 96143b6..efa8ab7 100644 --- a/R/create_project.R +++ b/R/create_project.R @@ -321,20 +321,43 @@ create_project <- function( file.create(paste0(path, "/.Rprofile")) } rprofile_content <- paste( + "# ---------------------------------------------------------", + "# This is the .Rprofile file", + "#", + "# Use it to include any functions you want to run before any other code", + "# is run.", + "# For example, using renv automatically sources its activate script to", + "# the .RProfile file", + "# This ensures that all renv checks on package versions happens before", + "# any code is run.", + "#", + "# ---------------------------------------------------------", + "", + "message('Sourcing .Rprofile..')", + "", + "source('renv/activate.R')", + "", + "# Welcome message", ".First <- function() {", - "if ('praise' %in% installed.packages()) {", - " message(praise::praise('${Exclamation}-${Exclamation}! '),", - " 'Welcome to your dfeR project.\\n',", - " praise::praise('Time for some ${adjective} R coding...'))", + " # Check if praise installed", + " if (system.file(package = 'praise') != '') {", + " welcome_msg <- message(", + " '\\n',", + " praise::praise('${Exclamation}-${Exclamation}! '),", + " 'Welcome to your dfeR project.\\n',", + " praise::praise('Time for some ${adjective} R coding...')", + " )", + "", + " welcome_msg", " } else {", - " message('Welcome to your dfeR project!\\n',", + " message('\\n',", + " 'Welcome to your dfeR project!\\n',", " 'To finish setting up renv, please do the following:\\n\\n',", " '- Run `renv::snapshot()`\\n',", " '- Select `2: Install the packages, then snapshot.`\\n',", " '- Finally type `y` to `Do you want to proceed?`\\n')", " }", "}", - "source('renv/activate.R')", sep = "\n" ) writeLines(rprofile_content, paste0(path, "/.Rprofile"))