1- # Supress R CMD check note
1+ # Suppress R CMD check note. memoise is used at build time!
22# ' @importFrom memoise memoise
33NULL
44
@@ -71,28 +71,25 @@ check_for_rstudio_updates <- function(
7171 )
7272}
7373
74- . r_release <- function () {
75- R_system_version(rversions :: r_release( )$ version )
74+ r_release <- function () {
75+ R_system_version(rversions :: resolve( " release " )$ version )
7676}
7777
78- r_release <- memoise :: memoise(.r_release )
79-
8078# ' Report package development situation
8179# '
82- # ' @template devtools
83- # ' @inheritParams pkgbuild::has_build_tools
84- # ' @description `dev_sitrep()` reports
85- # ' * If R is up to date
86- # ' * If RStudio is up to date
87- # ' * If compiler build tools are installed and available for use
88- # ' * If devtools and its dependencies are up to date
89- # ' * If the package's dependencies are up to date
80+ # ' @description
81+ # ' Call this function if things seem weird and you're not sure
82+ # ' what's wrong or how to fix it. It reports:
9083# '
91- # ' @description Call this function if things seem weird and you're not sure
92- # ' what's wrong or how to fix it. If this function returns no output
93- # ' everything should be ready for package development.
84+ # ' * If R is up to date.
85+ # ' * If RStudio or Positron is up to date.
86+ # ' * If compiler build tools are installed and available for use.
87+ # ' * If devtools and its dependencies are up to date.
88+ # ' * If the package's dependencies are up to date.
9489# '
9590# ' @return A named list, with S3 class `dev_sitrep` (for printing purposes).
91+ # ' @template devtools
92+ # ' @inheritParams pkgbuild::has_build_tools
9693# ' @export
9794# ' @examples
9895# ' \dontrun{
@@ -112,9 +109,9 @@ dev_sitrep <- function(pkg = ".", debug = FALSE) {
112109 has_build_tools = has_build_tools ,
113110 rtools_path = if (has_build_tools ) pkgbuild :: rtools_path(),
114111 devtools_version = utils :: packageVersion(" devtools" ),
115- devtools_deps = outdated_deps (pak :: pkg_deps(" devtools" , dependencies = NA )),
112+ devtools_deps = compare_deps (pak :: pkg_deps(" devtools" , dependencies = NA )),
116113 pkg_deps = if (! is.null(pkg )) {
117- outdated_deps (pak :: local_dev_deps(pkg $ path , dependencies = TRUE ))
114+ compare_deps (pak :: local_dev_deps(pkg $ path , dependencies = TRUE ))
118115 },
119116 rstudio_version = if (is_rstudio_running()) rstudioapi :: getVersion(),
120117 rstudio_msg = if (! is_positron()) check_for_rstudio_updates()
@@ -130,7 +127,7 @@ new_dev_sitrep <- function(
130127 has_build_tools = TRUE ,
131128 rtools_path = NULL ,
132129 devtools_version = utils :: packageVersion(" devtools" ),
133- devtools_deps = data.frame ( package = character (), diff = numeric ()) ,
130+ devtools_deps = NULL ,
134131 pkg_deps = NULL ,
135132 rstudio_version = NULL ,
136133 rstudio_msg = NULL
@@ -162,60 +159,84 @@ print.dev_sitrep <- function(x, ...) {
162159 kv_line(" version" , x $ r_version )
163160 kv_line(" path" , x $ r_path , path = TRUE )
164161 if (x $ r_version < x $ r_release_version ) {
162+ all_ok <- FALSE
165163 cli :: cli_bullets(c(
166164 " !" = " {.field R} is out of date ({.val {x$r_version}} vs {.val {x$r_release_version}})"
167165 ))
168- all_ok <- FALSE
169166 }
170167
171168 if (x $ is_windows ) {
172169 cli :: cli_rule(" Rtools" )
173170 if (x $ has_build_tools ) {
174171 kv_line(" path" , x $ rtools_path , path = TRUE )
175172 } else {
173+ all_ok <- FALSE
176174 cli :: cli_bullets(c(
177175 " !" = " {.field Rtools} is not installed." ,
178176 " " = " Download and install it from: {.url https://cloud.r-project.org/bin/windows/Rtools/}"
179177 ))
180178 }
181- all_ok <- FALSE
182179 }
183180
184181 if (! is.null(x $ rstudio_version )) {
185182 cli :: cli_rule(if (is_positron()) " Positron" else " RStudio" )
186183 kv_line(" version" , x $ rstudio_version )
187184
188185 if (! is.null(x $ rstudio_msg )) {
189- cli :: cli_bullets(c(" !" = " {x$rstudio_msg}" ))
190186 all_ok <- FALSE
187+ cli :: cli_bullets(c(" !" = " {x$rstudio_msg}" ))
191188 }
192189 }
193190
194191 cli :: cli_rule(" devtools" )
195192 kv_line(" version" , x $ devtools_version )
196193
197- devtools_deps_old <- x $ devtools_deps $ diff < 0
198- if (any(devtools_deps_old )) {
199- cli :: cli_bullets(c(
200- " !" = " {.pkg devtools} or its dependencies out of date:" ,
201- " " = " {.val {x$devtools_deps$package[devtools_deps_old]}}" ,
202- " " = " Update them with {.code pak::pak(\" devtools\" )}"
203- ))
194+ devtools_not_ok <- any(x $ devtools_deps $ status != " ok" )
195+ if (devtools_not_ok ) {
204196 all_ok <- FALSE
197+
198+ behind <- x $ devtools_deps [x $ devtools_deps $ status == " behind" , ]
199+ if (nrow(behind ) > 0 ) {
200+ cli :: cli_bullets(c(
201+ " !" = " {.field devtools} or its dependencies are out of date." ,
202+ " " = " Update them with {.code pak::pak(\" devtools\" ).}"
203+ ))
204+ cli :: cli_verbatim(paste(" " , dep_labels(behind )))
205+ }
206+
207+ ahead <- x $ devtools_deps [x $ devtools_deps $ status == " ahead" , ]
208+ if (nrow(ahead ) > 0 ) {
209+ cli :: cli_bullets(c(
210+ " i" = " {.field devtools} or its dependencies are installed from a dev version, FYI:"
211+ ))
212+ cli :: cli_verbatim(paste(" " , dep_labels(ahead )))
213+ }
205214 }
206215
207216 cli :: cli_rule(" dev package" )
208217 kv_line(" package" , x $ pkg $ package )
209218 kv_line(" path" , x $ pkg $ path , path = TRUE )
210219
211- pkg_deps_old <- x $ pkg_deps $ diff < 0
212- if (any(pkg_deps_old )) {
213- cli :: cli_bullets(c(
214- " !" = " {.field {x$pkg$package}} dependencies out of date:" ,
215- " " = " {.val {x$pkg_deps$package[pkg_deps_old]}}" ,
216- " " = " Update them with {.code pak::local_install_dev_deps()}"
217- ))
220+ dev_pkg_not_ok <- any(x $ pkg_deps $ status != " ok" )
221+ if (dev_pkg_not_ok ) {
218222 all_ok <- FALSE
223+
224+ behind <- x $ pkg_deps [x $ pkg_deps $ status == " behind" , ]
225+ if (nrow(behind ) > 0 ) {
226+ cli :: cli_bullets(c(
227+ " !" = " {.field {x$pkg$package}} dependencies are out of date." ,
228+ " " = " Update them with {.code pak::local_install_dev_deps()}."
229+ ))
230+ cli :: cli_verbatim(paste(" " , dep_labels(behind )))
231+ }
232+
233+ ahead <- x $ pkg_deps [x $ pkg_deps $ status == " ahead" , ]
234+ if (nrow(ahead ) > 0 ) {
235+ cli :: cli_bullets(c(
236+ " i" = " {.field {x$pkg$package}} dependencies are installed from a dev version, FYI:"
237+ ))
238+ cli :: cli_verbatim(paste(" " , dep_labels(ahead )))
239+ }
219240 }
220241
221242 if (all_ok ) {
@@ -225,10 +246,9 @@ print.dev_sitrep <- function(x, ...) {
225246 invisible (x )
226247}
227248
228-
229249# Helpers -----------------------------------------------------------------
230250
231- outdated_deps <- function (deps ) {
251+ compare_deps <- function (deps ) {
232252 installed <- vapply(
233253 deps $ package ,
234254 function (p ) {
@@ -239,18 +259,53 @@ outdated_deps <- function(deps) {
239259 },
240260 character (1 )
241261 )
242- diff <- mapply(
243- function (inst , avail ) {
262+ status <- mapply(
263+ function (inst , latest ) {
244264 if (is.na(inst )) {
245- return (- 1L )
265+ return (" behind " )
246266 }
247- as.integer(utils :: compareVersion(inst , avail ))
267+ switch (
268+ as.character(utils :: compareVersion(inst , latest )),
269+ " -1" = " behind" ,
270+ " 0" = " ok" ,
271+ " 1" = " ahead"
272+ )
248273 },
249274 installed ,
250275 deps $ version ,
251276 USE.NAMES = FALSE
252277 )
253- data.frame (package = deps $ package , diff = diff )
278+ data.frame (
279+ package = deps $ package ,
280+ latest = deps $ version ,
281+ installed = installed ,
282+ status = status
283+ )
284+ }
285+
286+ dep_labels <- function (deps ) {
287+ labels <- mapply(
288+ format_dep_line ,
289+ format(deps $ package , justify = " left" ),
290+ deps $ installed ,
291+ deps $ latest ,
292+ deps $ status ,
293+ USE.NAMES = FALSE
294+ )
295+ stats :: setNames(labels , rep(" " , length(labels )))
296+ }
297+
298+ format_dep_line <- function (package , installed , latest , status ) {
299+ if (is.na(installed )) {
300+ paste0(package , " (not installed)" )
301+ } else {
302+ status_styled <- if (status == " behind" ) {
303+ cli :: col_red(status )
304+ } else {
305+ cli :: col_cyan(status )
306+ }
307+ paste0(package , " (" , status_styled , " : " , installed , " vs " , latest , " )" )
308+ }
254309}
255310
256311kv_line <- function (key , value , path = FALSE ) {
0 commit comments