Skip to content

Commit

Permalink
linter
Browse files Browse the repository at this point in the history
  • Loading branch information
ColinFay committed Feb 10, 2022
1 parent a739ca1 commit 10e559d
Show file tree
Hide file tree
Showing 58 changed files with 1,757 additions and 2,026 deletions.
480 changes: 107 additions & 373 deletions R/add_dockerfiles.R

Large diffs are not rendered by default.

428 changes: 215 additions & 213 deletions R/add_files.R

Large diffs are not rendered by default.

59 changes: 34 additions & 25 deletions R/add_r_files.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#' @importFrom fs path_abs path file_create
add_r_files <- function(name,
ext = c("fct", "utils"),
module = "",
pkg = get_golem_wd(),
open = TRUE,
dir_create = TRUE,
with_test = FALSE) {
add_r_files <- function(
name,
ext = c("fct", "utils"),
module = "",
pkg = get_golem_wd(),
open = TRUE,
dir_create = TRUE,
with_test = FALSE
) {
name <- file_path_sans_ext(name)

old <- setwd(path_abs(pkg))
Expand Down Expand Up @@ -40,7 +42,8 @@ add_r_files <- function(name,
}

where <- path(
"R", paste0(module, ext, "_", name, ".R")
"R",
paste0(module, ext, "_", name, ".R")
)

if (!file_exists(where)) {
Expand Down Expand Up @@ -92,12 +95,14 @@ add_r_files <- function(name,
#' @export
#'
#' @return The path to the file, invisibly.
add_fct <- function(name,
module = NULL,
pkg = get_golem_wd(),
open = TRUE,
dir_create = TRUE,
with_test = FALSE) {
add_fct <- function(
name,
module = NULL,
pkg = get_golem_wd(),
open = TRUE,
dir_create = TRUE,
with_test = FALSE
) {
add_r_files(
name,
module,
Expand All @@ -111,12 +116,14 @@ add_fct <- function(name,

#' @rdname file_creation
#' @export
add_utils <- function(name,
module = NULL,
pkg = get_golem_wd(),
open = TRUE,
dir_create = TRUE,
with_test = FALSE) {
add_utils <- function(
name,
module = NULL,
pkg = get_golem_wd(),
open = TRUE,
dir_create = TRUE,
with_test = FALSE
) {
add_r_files(
name,
module,
Expand All @@ -139,10 +146,12 @@ add_utils <- function(name,
#'
#' @rdname file_creation
#' @noRd
append_roxygen_comment <- function(name,
path,
ext,
export = FALSE) {
append_roxygen_comment <- function(
name,
path,
ext,
export = FALSE
) {
write_there <- function(...) {
write(..., file = path, append = TRUE)
}
Expand All @@ -166,4 +175,4 @@ append_roxygen_comment <- function(name,
} else {
write_there("#' @noRd")
}
}
}
13 changes: 6 additions & 7 deletions R/add_resource_path.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,23 @@
#' If TRUE display message if directory is empty.
#'
#' @importFrom shiny addResourcePath
#'
#'
#' @export
#'
#' @return Used for side effects.
add_resource_path <- function(
prefix,
prefix,
directoryPath,
warn_empty = FALSE
){

) {
list_f <- length(
list.files(
path = directoryPath
)
) == 0
if ( list_f ) {
if (warn_empty){

if (list_f) {
if (warn_empty) {
warning("No resources to add from resource path (directory empty).")
}
} else {
Expand Down
78 changes: 38 additions & 40 deletions R/add_rstudio_files.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,28 @@
#' @importFrom fs path file_create path_file
add_rstudio_files <- function(
pkg,
open,
open,
service = c(
"RStudio Connect",
"Shiny Server",
"RStudio Connect",
"Shiny Server",
"ShinyApps.io"
)
){
) {
service <- match.arg(service)
where <- path(pkg, "app.R")

disable_autoload(
pkg = pkg
)


if (!file_exists(where)){
file_create( where )

write_there <- function(..., here = where){

if (!file_exists(where)) {
file_create(where)

write_there <- function(..., here = where) {
write(..., here, append = TRUE)
}
use_build_ignore( path_file(where) )

use_build_ignore(path_file(where))
use_build_ignore("rsconnect")
write_there("# Launch the ShinyApp (Do not remove this comment)")
write_there("# To deploy, run: rsconnect::deployApp()")
Expand All @@ -37,11 +36,11 @@ add_rstudio_files <- function(
write_there("options( \"golem.app.prod\" = TRUE)")
write_there(
sprintf(
"%s::run_app() # add parameters here (if any)",
"%s::run_app() # add parameters here (if any)",
get_golem_name()
)
)

x <- capture.output(use_package("pkgload"))
cat_created(where)
cat_line("To deploy, run:")
Expand All @@ -52,76 +51,75 @@ add_rstudio_files <- function(
service
)
)

open_or_go_to(where, open)
} else {
file_already_there_dance(
where = where,
where = where,
open_file = open
)
}

}

#' Add an app.R at the root of your package to deploy on RStudio Connect
#'
#' @note
#' @note
#' In previous versions, this function was called add_rconnect_file.
#'
#' @inheritParams add_module
#' @aliases add_rconnect_file add_rstudioconnect_file
#' @export
#'
#'
#' @rdname rstudio_deploy
#'
#'
#' @return The path to the file, invisibly.
#'
#'
#' @examples
#' # Add a file for Connect
#' if (interactive()){
#' add_rstudioconnect_file()
#' if (interactive()) {
#' add_rstudioconnect_file()
#' }
#' # Add a file for Shiny Server
#' if (interactive()){
#' add_shinyserver_file()
#' if (interactive()) {
#' add_shinyserver_file()
#' }
#' # Add a file for Shinyapps.io
#' if (interactive()){
#' add_shinyappsio_file()
#' if (interactive()) {
#' add_shinyappsio_file()
#' }
add_rstudioconnect_file <- function(
pkg = get_golem_wd(),
pkg = get_golem_wd(),
open = TRUE
){
) {
add_rstudio_files(
pkg = pkg,
open = open,
pkg = pkg,
open = open,
service = "RStudio Connect"
)
}

#' @rdname rstudio_deploy
#' @export
add_shinyappsio_file <- function(
pkg = get_golem_wd(),
pkg = get_golem_wd(),
open = TRUE
){
) {
add_rstudio_files(
pkg = pkg,
open = open,
pkg = pkg,
open = open,
service = "ShinyApps.io"
)
}

#' @rdname rstudio_deploy
#' @export
add_shinyserver_file <- function(
pkg = get_golem_wd(),
pkg = get_golem_wd(),
open = TRUE
){
) {
add_rstudio_files(
pkg = pkg,
open = open,
pkg = pkg,
open = open,
service = "Shiny Server"
)
}
11 changes: 7 additions & 4 deletions R/addins.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,13 @@ insert_ns <- function() {
}

#' @importFrom fs path file_exists
go_to <- function(file,
wd = golem::get_golem_wd()) {
go_to <- function(
file,
wd = golem::get_golem_wd()
) {
file <- path(
wd, file
wd,
file
)
if (!file_exists(file)) {
message(file, "not found.")
Expand Down Expand Up @@ -89,4 +92,4 @@ go_to_app_server <- function() {
#' @aliases addins
go_to_run_app <- function() {
go_to("R/run_app.R")
}
}
13 changes: 6 additions & 7 deletions R/browser_button.R
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
#' Insert an hidden browser button
#'
#'
#' See \url{https://rtask.thinkr.fr/a-little-trick-for-debugging-shiny/} for more context.
#'
#' @return Used for side effects.
#' Prints the code to the console.
#' @export
#'
#'
#' @importFrom cli cat_rule cat_line
browser_button <- function(){
browser_button <- function() {
cat_rule("To be copied in your UI")
cat_line(darkgrey('actionButton("browser", "browser"),'))
cat_line(darkgrey('tags$script("$(\'#browser\').hide();")'))
cat_line()
cat_rule("To be copied in your server")
cat_line(darkgrey('observeEvent(input$browser,{'))
cat_line(darkgrey(' browser()'))
cat_line(darkgrey('})'))
cat_line(darkgrey("observeEvent(input$browser,{"))
cat_line(darkgrey(" browser()"))
cat_line(darkgrey("})"))
cat_line()
cat_line("By default, this button will be hidden.")
cat_line("To show it, open your web browser JavaScript console")
cat_line("And run $('#browser').show();")
}

Loading

0 comments on commit 10e559d

Please sign in to comment.