Skip to content

Commit 09b8a5f

Browse files
authored
Merge pull request #133 from SpatLyu/master
explicitly namespace function calls using pkg::fun() to improve clarity and avoid ambiguity
2 parents eb9a9d5 + 0a42ef4 commit 09b8a5f

File tree

12 files changed

+119
-116
lines changed

12 files changed

+119
-116
lines changed

.github/workflows/R-CMD-check.yaml

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,39 @@ on:
55
branches: [main, master]
66
pull_request:
77

8-
name: R-CMD-check.yaml
8+
name: R-CMD-check
99

1010
permissions: read-all
1111

1212
jobs:
1313
R-CMD-check:
14-
runs-on: ubuntu-latest
14+
runs-on: ${{ matrix.config.os }}
15+
16+
name: ${{ matrix.config.os }} (${{ matrix.config.r }})
17+
18+
strategy:
19+
fail-fast: false
20+
matrix:
21+
config:
22+
- {os: macos-latest, r: 'release'}
23+
- {os: windows-latest, r: 'release'}
24+
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
25+
- {os: ubuntu-latest, r: 'release'}
26+
- {os: ubuntu-latest, r: 'oldrel-1'}
27+
1528
env:
1629
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
1730
R_KEEP_PKG_SOURCE: yes
31+
1832
steps:
1933
- uses: actions/checkout@v4
2034

35+
- uses: r-lib/actions/setup-pandoc@v2
36+
2137
- uses: r-lib/actions/setup-r@v2
2238
with:
39+
r-version: ${{ matrix.config.r }}
40+
http-user-agent: ${{ matrix.config.http-user-agent }}
2341
use-public-rspm: true
2442

2543
- uses: r-lib/actions/setup-r-dependencies@v2

DESCRIPTION

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ Imports:
3838
sf (>= 0.5-2),
3939
shiny,
4040
tmaptools,
41-
shinyWidgets (>= 0.4.3)
41+
shinyWidgets (>= 0.4.3),
42+
magrittr
4243
Suggests:
4344
crayon,
4445
sp

NAMESPACE

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ S3method(editMap,mapview)
88
S3method(selectFeatures,Spatial)
99
S3method(selectFeatures,sf)
1010
S3method(selectMap,leaflet)
11+
export("%>%")
1112
export(createFeatures)
1213
export(drawFeatures)
1314
export(editAttributes)
@@ -19,26 +20,4 @@ export(selectFeatures)
1920
export(selectMap)
2021
export(selectMod)
2122
export(selectModUI)
22-
import(dplyr)
23-
import(htmltools)
24-
import(leafem)
25-
import(leaflet)
26-
import(leafpop)
27-
import(mapview)
28-
import(sf)
29-
import(shiny)
30-
importFrom(dplyr,bind_rows)
31-
importFrom(leaflet,setView)
32-
importFrom(mapview,mapview)
33-
importFrom(miniUI,gadgetTitleBar)
34-
importFrom(miniUI,miniButtonBlock)
35-
importFrom(miniUI,miniContentPanel)
36-
importFrom(miniUI,miniPage)
37-
importFrom(rstudioapi,getActiveDocumentContext)
38-
importFrom(sf,write_sf)
39-
importFrom(shinyWidgets,actionBttn)
40-
importFrom(shinyWidgets,show_alert)
41-
importFrom(shinyWidgets,switchInput)
42-
importFrom(shinyWidgets,updateSwitchInput)
43-
importFrom(shinyWidgets,useSweetAlert)
44-
importFrom(tmaptools,geocode_OSM)
23+
importFrom(magrittr,"%>%")

R/addin.R

Lines changed: 24 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
2-
3-
41
#' @title mapedit create features Addin
52
#' @description Create and save spatial objects within the Rstudio IDE. Objects
63
#' can then be saved to file types such as \code{.geojson} or \code{.shp}.
@@ -17,30 +14,22 @@
1714
#' @param SF_OBJECT sf Simple feature collection
1815
#'
1916
#' @return sf object and/or saved to file
20-
#' @importFrom miniUI miniPage miniContentPanel gadgetTitleBar miniButtonBlock
21-
#' @import shiny
22-
#' @importFrom shinyWidgets switchInput updateSwitchInput
23-
#' @importFrom mapview mapview
24-
#' @importFrom sf write_sf
25-
#' @importFrom dplyr bind_rows
26-
#' @importFrom leaflet setView
27-
#' @importFrom rstudioapi getActiveDocumentContext
2817
#' @export
2918
#'
3019
createFeatures <- function(SF_OBJECT = NULL) {
3120

32-
ui <- miniPage(
33-
gadgetTitleBar("Edit Map"),
34-
miniContentPanel(
35-
editModUI("editor"),
36-
miniButtonBlock(
37-
div(style="display: inline-block;padding-top:22px;padding-left:30px;width:200px;",
38-
switchInput('savefile', 'Save', value = FALSE, onStatus = "success", offStatus = "danger")),
39-
div(style="display: inline-block; width: 400px;",
40-
textInput('filename', '', value = 'saved_geometry.geojson')),
41-
div(style="display: inline-block;padding-top:18px;width: 400px;font-size: 10pt;color: #313844;",
42-
'The filename can include a path relative to working directory. ',
43-
'A different file type can be selected by changing the file extension.')
21+
ui <- miniUI::miniPage(
22+
miniUI::gadgetTitleBar("Edit Map"),
23+
miniUI::miniContentPanel(
24+
mapedit::editModUI("editor"),
25+
miniUI::miniButtonBlock(
26+
htmltools::div(style="display: inline-block;padding-top:22px;padding-left:30px;width:200px;",
27+
shinyWidgets::switchInput('savefile', 'Save', value = FALSE, onStatus = "success", offStatus = "danger")),
28+
htmltools::div(style="display: inline-block; width: 400px;",
29+
shiny::textInput('filename', '', value = 'saved_geometry.geojson')),
30+
htmltools::div(style="display: inline-block;padding-top:18px;width: 400px;font-size: 10pt;color: #313844;",
31+
'The filename can include a path relative to working directory. ',
32+
'A different file type can be selected by changing the file extension.')
4433
)
4534
)
4635
)
@@ -63,36 +52,38 @@ createFeatures <- function(SF_OBJECT = NULL) {
6352
}, silent = TRUE)
6453

6554
# update UI based on inputs
66-
updateTextInput(session, 'filename', value = FILENAME)
55+
shiny::updateTextInput(session, 'filename', value = FILENAME)
6756
if (FILENAME != 'saved_geometry.geojson') {
68-
updateSwitchInput(session, 'savefile', value = TRUE)
57+
shinyWidgets::updateSwitchInput(session, 'savefile', value = TRUE)
6958
}
7059

7160
# load mapedit
7261
if ('sf' %in% class(SF_OBJECT)) {
73-
geo <- callModule(editMod, "editor", mapview(SF_OBJECT)@map)
62+
geo <- shiny::callModule(mapedit::editMod, "editor", mapview::mapview(SF_OBJECT)@map)
7463
} else {
75-
geo <- callModule(editMod, "editor", setView(mapview()@map, 80, 0, 3))
64+
geo <- shiny::callModule(mapedit::editMod, "editor", leaflet::setView(mapview::mapview()@map, 80, 0, 3))
7665
}
7766

78-
observe({
67+
shiny::observe({
7968
input$filename
8069
OBJECTNAME <- tools::file_path_sans_ext(basename(input$filename))
8170
})
8271

8372
# return geometry to file and object in console
84-
observeEvent(input$done, {
73+
shiny::observeEvent(input$done, {
8574
geom <- geo()$finished
8675

87-
if (!is.null(geom) & !is.null(SF_OBJECT)) geom <- dplyr::bind_rows(SF_OBJECT, geom)
76+
if (!is.null(geom) & !is.null(SF_OBJECT)) {
77+
geom <- dplyr::bind_rows(SF_OBJECT, geom)
78+
}
8879

8980
if (!is.null(geom)) {
9081
if (input$savefile) {
9182
sf::write_sf(geom, input$filename, delete_layer = TRUE, delete_dsn = TRUE)
9283
}
9384
}
9485

95-
stopApp({
86+
shiny::stopApp({
9687
if (!is.null(geom)) {
9788
geom
9889
}
@@ -101,7 +92,7 @@ createFeatures <- function(SF_OBJECT = NULL) {
10192

10293
}
10394

104-
viewer <- paneViewer(600)
105-
runGadget(ui, server, viewer = viewer)
95+
viewer <- shiny::paneViewer(600)
96+
shiny::runGadget(ui, server, viewer = viewer)
10697

10798
}

R/edit.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ editMap.leaflet <- function(
7777
title = title,
7878
right = miniUI::miniTitleBarButton("done", "Done", primary = TRUE)
7979
),
80-
tags$script(HTML(
80+
htmltools::tags$script(htmltools::HTML(
8181
"
8282
// close browser window on session end
8383
$(document).on('shiny:disconnected', function() {
@@ -95,7 +95,7 @@ $(document).on('shiny:disconnected', function() {
9595
)
9696

9797
server <- function(input, output, session) {
98-
crud <- callModule(
98+
crud <- shiny::callModule(
9999
editMod,
100100
ns,
101101
x,
@@ -107,7 +107,7 @@ $(document).on('shiny:disconnected', function() {
107107
editorOptions = editorOptions
108108
)
109109

110-
observe({crud()})
110+
shiny::observe({crud()})
111111

112112
# if browser viewer and user closes tab/window
113113
# then Shiny does not stop so we will stopApp
@@ -117,7 +117,7 @@ $(document).on('shiny:disconnected', function() {
117117
sessionEnded <- session$onSessionEnded(function() {
118118
# should this be a cancel where we send NULL
119119
# or a done where we send crud()
120-
shiny::stopApp(isolate(crud()))
120+
shiny::stopApp(shiny::isolate(crud()))
121121
})
122122

123123
shiny::observeEvent(input$done, {

R/editAttributes.R

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,6 @@
3434
#' @note Editing of feature geometries does not work for multi-geometry inputs. For this use case it is advisable to
3535
#' split the data set by geometry type and edit separately
3636
#'
37-
#' @import sf
38-
#' @import leaflet
39-
#' @import mapview
40-
#' @import leafem
41-
#' @import leafpop
42-
#' @import dplyr
43-
#' @import shiny
44-
#' @import htmltools
45-
#' @importFrom shinyWidgets actionBttn show_alert useSweetAlert
46-
#' @importFrom tmaptools geocode_OSM
47-
#'
4837
#' @return sf data.frame
4938
#' @export
5039
#'
@@ -81,7 +70,8 @@ editAttributes <- function(dat, zoomto = NULL, col_add = TRUE, reset = TRUE, pro
8170

8271
#create base df if dat missing
8372
if (missing(dat)) {
84-
dat <- data.frame(id = 'CHANGE ME', comments = 'ADD COMMENTS...') %>% mutate(leaf_id = 1)
73+
dat <- data.frame(id = 'CHANGE ME', comments = 'ADD COMMENTS...') %>%
74+
dplyr::mutate(leaf_id = 1)
8575
if (is.null(zoomto)) {
8676
message(MSG)
8777
zoomto <- DEFAULT_ZOOM
@@ -97,13 +87,13 @@ editAttributes <- function(dat, zoomto = NULL, col_add = TRUE, reset = TRUE, pro
9787
original_sf <- NULL
9888
if (all(class(dat) == 'list')) {
9989
original_sf <- lapply(dat, function(df){
100-
df %>% mutate(leaf_id = 1:nrow(df))
90+
df %>% dplyr::mutate(leaf_id = 1:nrow(df))
10191
})
102-
dat <- bind_rows(dat) %>% mutate(leaf_id = 1:nrow(dat))
92+
dat <- dplyr::bind_rows(dat) %>% dplyr::mutate(leaf_id = 1:nrow(dat))
10393
}
10494

10595
if (all(class(dat) == 'data.frame')) {
106-
dat <- dat %>% mutate(leaf_id = 1:nrow(dat))
96+
dat <- dat %>% dplyr::mutate(leaf_id = 1:nrow(dat))
10797
data_copy <- sf::st_as_sf(
10898
dat,
10999
geometry = sf::st_sfc(lapply(seq_len(nrow(dat)),function(i){sf::st_point()}))
@@ -119,7 +109,7 @@ editAttributes <- function(dat, zoomto = NULL, col_add = TRUE, reset = TRUE, pro
119109

120110
} else if (any(type %in% class(dat))) {
121111

122-
dat <- dat %>% mutate(leaf_id = 1:nrow(dat)) %>% sf::st_transform(APP_CRS)
112+
dat <- dat %>% dplyr::mutate(leaf_id = 1:nrow(dat)) %>% sf::st_transform(APP_CRS)
123113
data_copy <- dat # TODO check orig crs and transform to 4326
124114

125115
if(is.na(sf::st_crs(dat))){dat <- dat %>% sf::st_set_crs(APP_CRS)}
@@ -144,13 +134,13 @@ editAttributes <- function(dat, zoomto = NULL, col_add = TRUE, reset = TRUE, pro
144134
}
145135

146136

147-
ui <- tagList(
137+
ui <- htmltools::tagList(
148138
shinyWidgets::useSweetAlert(),
149139
shiny::fluidPage(
150140
shiny::fluidRow(
151141
shiny::column(12, editModUI("map"))
152142
),
153-
tags$hr(),
143+
htmltools::tags$hr(),
154144
shiny::fluidRow(
155145
shiny::column(ifelse(col_add, 6, 9),
156146
DT::dataTableOutput("tbl",width="100%", height=200)),
@@ -182,7 +172,7 @@ editAttributes <- function(dat, zoomto = NULL, col_add = TRUE, reset = TRUE, pro
182172
}
183173
}
184174
),
185-
shiny::fluidRow(tags$hr(),
175+
shiny::fluidRow(htmltools::tags$hr(),
186176
shiny::div(style = 'padding: 20px',
187177
shinyWidgets::actionBttn("donebtn", "Done",
188178
icon = shiny::icon('check-circle'),
@@ -269,7 +259,7 @@ editAttributes <- function(dat, zoomto = NULL, col_add = TRUE, reset = TRUE, pro
269259

270260
output$dyn_form <- shiny::renderUI({
271261

272-
shiny::tagList(
262+
htmltools::tagList(
273263
lapply(1:length(df$types), function(n){
274264
name <- names(df$types[n])
275265
label <- paste0(names(df$types[n]), ' (', df$types[n], ')')
@@ -502,7 +492,7 @@ editAttributes <- function(dat, zoomto = NULL, col_add = TRUE, reset = TRUE, pro
502492
proxy_map %>%
503493
leaflet::flyTo(lng = pnt$X, lat = pnt$Y, zoom = input[[nsm('map_zoom')]])
504494
} else {
505-
bb <- st_bbox(sf::st_geometry(rowsel))
495+
bb <- sf::st_bbox(sf::st_geometry(rowsel))
506496
proxy_map %>%
507497
leaflet::flyToBounds(bb[['xmin']], bb[['ymin']], bb[['xmax']], bb[['ymax']])
508498
}

R/helpers.R

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,16 @@ insane_longitude_warning = function() {
88
call. = FALSE)
99
}
1010
}
11+
12+
#' @title Pipe operator
13+
#' @description
14+
#' See \code{magrittr::\link[magrittr:pipe]{\%>\%}} for details.
15+
#'
16+
#' @name %>%
17+
#' @usage lhs \%>\% rhs
18+
#' @rdname pipe
19+
#' @keywords internal
20+
#' @importFrom magrittr %>%
21+
#' @return `NULL` (this is the magrittr pipe operator)
22+
#' @export
23+
NULL

0 commit comments

Comments
 (0)