Просмотр исходного кода

Announce package updates via modal on first gadget launch

tags/v0.1.5
Garrick Aden-Buie 8 лет назад
Родитель
Сommit
5333e63c33
6 измененных файлов: 100 добавлений и 2 удалений
  1. +2
    -1
      DESCRIPTION
  2. +2
    -0
      NAMESPACE
  3. +2
    -0
      NEWS.md
  4. +68
    -0
      R/regex_gadget.R
  5. +1
    -1
      R/regexplain-package.R
  6. +25
    -0
      man/check_version.Rd

+ 2
- 1
DESCRIPTION Просмотреть файл

@@ -27,7 +27,8 @@ Imports:
tidyr,
rstudioapi,
shiny,
miniUI
miniUI,
jsonlite
RoxygenNote: 6.0.1
Roxygen: list(markdown = TRUE)
URL: https://github.com/gadenbuie/regexplain

+ 2
- 0
NAMESPACE Просмотреть файл

@@ -14,3 +14,5 @@ importFrom(dplyr,select)
importFrom(dplyr,summarize)
importFrom(rlang,.data)
importFrom(utils,getFromNamespace)
importFrom(utils,installed.packages)
importFrom(utils,packageVersion)

+ 2
- 0
NEWS.md Просмотреть файл

@@ -4,6 +4,8 @@

* Options from **Regex** tab are extended to **Output** tab as well. Colored
options according to group where they are applied.
* Added a mechanism to announce package updates while this package is on GitHub.
Only checked once per R session on the first launch of the gadget.

### 0.1.4


+ 68
- 0
R/regex_gadget.R Просмотреть файл

@@ -10,6 +10,8 @@ regex_gadget <- function(text = NULL,
start_page = if (is.null(text)) "Text" else "Regex") {
stopifnot(requireNamespace("miniUI"), requireNamespace("shiny"))

update_available <- check_version()

# ---- UI ----
ui <- miniPage(
shiny::includeCSS(system.file("styles", "style.css", package = "regexplain")),
@@ -116,6 +118,33 @@ regex_gadget <- function(text = NULL,

# ---- Server ----
server <- function(input, output, session) {
if (!is.null(update_available)) {
showModal(
modalDialog(
title = "Update Available \U1F389",
easyClose = TRUE,
footer = modalButton("OK"),
tagList(
tags$p(
"Version", update_available$version, "is",
tags$a(href = update_available$link,
"available on GitHub.")
),
if ("devtools" %in% installed.packages()) tags$p(
"The fastest way to update is with devtools:",
tags$pre(
"devtools::update_packages(\"gadenbuie/regexplain\")"
)
),
tags$p(
class = 'help-block',
"This message won't be shown again during this R session."
)
)
)
)
}

# ---- Server - Global ----
rtext <- reactive({
x <- if ('text_break_lines' %in% input$regex_options) {
@@ -326,3 +355,42 @@ get_pkg_namespace <- function(fn) {
x
}

#' Check if an updated version is available
#'
#' I included this because it can be difficult to tell if your RStudio Addins
#' are up to date. I may add new features that you want but you won't hear about
#' the updates. This function checks if an update is available, using GitHub
#' tags. If an update is available, a modal dialog is shown when you start
#' the regexplain gadget. This only happens once per R session, though, so feel
#' free to ignore the message.
#'
#' @param gh_user GitHub user account
#' @param gh_repo GitHub repo name
#' @param this_version The currently installed version of the package
#' @keywords internal
check_version <- function(
gh_user = "gadenbuie",
gh_repo = "regexplain",
this_version = packageVersion('regexplain')
) {
ok_to_check <- getOption("regexplain.no.check.version", TRUE)
if (!ok_to_check) return(NULL)
if (!requireNamespace('jsonlite', quietly = TRUE)) return(NULL)
gh_tags <- jsonlite::fromJSON(
paste0("https://api.github.com/repos/", gh_user, "/", gh_repo, "/git/refs/tags"),
simplifyDataFrame = TRUE
)
gh_tags$tag <- sub("refs/tags/", "", gh_tags$ref, fixed = TRUE)
gh_tags$version <- sub("^v\\.?", "", gh_tags$tag)
if (any(gh_tags$version > this_version)) {
max_version <- max(gh_tags$version)
max_tag <- gh_tags$tag[gh_tags$version == max_version]
options(regexplain.no.check.version = FALSE)
return(
list(
version = max_version,
link = paste("https://github.com", gh_user, gh_repo, "releases/tag", max_tag, sep = "/")
)
)
} else return(NULL)
}

+ 1
- 1
R/regexplain-package.R Просмотреть файл

@@ -1,4 +1,4 @@
#' @importFrom dplyr "%>%" mutate filter group_by summarize select
#' @importFrom utils getFromNamespace
#' @importFrom utils getFromNamespace installed.packages packageVersion
#' @keywords internal
"_PACKAGE"

+ 25
- 0
man/check_version.Rd Просмотреть файл

@@ -0,0 +1,25 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/regex_gadget.R
\name{check_version}
\alias{check_version}
\title{Check if an updated version is available}
\usage{
check_version(gh_user = "gadenbuie", gh_repo = "regexplain",
this_version = packageVersion("regexplain"))
}
\arguments{
\item{gh_user}{GitHub user account}

\item{gh_repo}{GitHub repo name}

\item{this_version}{The currently installed version of the package}
}
\description{
I included this because it can be difficult to tell if your RStudio Addins
are up to date. I may add new features that you want but you won't hear about
the updates. This function checks if an update is available, using GitHub
tags. If an update is available, a modal dialog is shown when you start
the regexplain gadget. This only happens once per R session, though, so feel
free to ignore the message.
}
\keyword{internal}

Загрузка…
Отмена
Сохранить