Skip to content

Commit 26f5673

Browse files
authored
Merge pull request #5 from guidomaggioorg/develop
myfinalpkg 1.1.0
2 parents 70de494 + d1bc9fe commit 26f5673

File tree

7 files changed

+206
-19
lines changed

7 files changed

+206
-19
lines changed

.github/workflows/workflow.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ on:
1111
pull_request:
1212
# Allow manual runs from the Actions tab
1313
workflow_dispatch:
14-
schedule:
15-
- cron: '*/10 * * * 4'
14+
# schedule:
15+
# - cron: '*/10 * * * 4'
1616

1717
jobs:
1818
CI-CD:

DESCRIPTION

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: myfinalpkg
22
Title: IntroR4 example pkg
3-
Version: 1.0.0
3+
Version: 1.1.0
44
Author: Guido Maggio
55
Maintainer: Guido Maggio <[email protected]>
66
Description: Example package for IntroR4 workshop.
@@ -14,6 +14,7 @@ Depends:
1414
Imports:
1515
dplyr,
1616
ggplot2,
17+
plotly,
1718
scales,
1819
utils,
1920
zoo

NAMESPACE

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export(roll_mean)
99
import(dplyr)
1010
import(ggplot2)
1111
importFrom(dplyr,filter)
12+
importFrom(plotly,ggplotly)
1213
importFrom(scales,cut_si)
1314
importFrom(scales,label_number)
1415
importFrom(utils,read.csv)

NEWS.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# myfinalpkg 1.1.0
2+
3+
* Added News md file to track releases (#1).
4+
* Add plotly graphs (#3)
5+
6+
# myfinalpkg 1.0.0
7+
8+
* 1st version of myfinalpkg.

R/plots_utils.R

+14-8
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ get_date_breaks <- function(dates, threshold = 160) {
8585
#'
8686
#' @import dplyr
8787
#' @import ggplot2
88+
#' @importFrom plotly ggplotly
8889
#' @importFrom dplyr filter
8990
#' @export
9091
#'
@@ -97,14 +98,14 @@ get_date_breaks <- function(dates, threshold = 160) {
9798
line_plot_data <- function(data, value, startdate = data$Date[1], title) {
9899
if (!(value %in% names(data)))
99100
stop(value, " is not a valid column name of data")
100-
101+
101102
if (!missing(startdate)) {
102103
# conflicts with "stats" package, ::: could be required
103104
data <- data %>%
104105
filter(Date >= startdate)
105106
}
106107
date.break <- get_date_breaks(data$Date)
107-
108+
108109
p <- ggplot(data, aes(
109110
x = Date,
110111
y = !!sym(value),
@@ -119,7 +120,9 @@ line_plot_data <- function(data, value, startdate = data$Date[1], title) {
119120
#add title if present
120121
if (!missing(title))
121122
p <- p + labs(title = title)
122-
p
123+
pp <- p %>%
124+
ggplotly(tooltip = c("x", "y"))
125+
pp
123126
}
124127

125128
#' Barplot function
@@ -136,6 +139,7 @@ line_plot_data <- function(data, value, startdate = data$Date[1], title) {
136139
#'
137140
#' @import dplyr
138141
#' @import ggplot2
142+
#' @importFrom plotly ggplotly
139143
#' @importFrom dplyr filter
140144
#' @export
141145
#'
@@ -148,21 +152,21 @@ line_plot_data <- function(data, value, startdate = data$Date[1], title) {
148152
bar_plot_data <- function(data, value, startdate = data$Date[1], rollm = FALSE, title) {
149153
if (!(value %in% names(data)))
150154
stop(value, " is not a valid column name of data")
151-
155+
152156
if (!missing(startdate)) {
153157
# conflicts with "stats" package, ::: could be required
154158
data <- data %>%
155159
filter(Date >= startdate)
156160
}
157161
date.break <- get_date_breaks(data$Date)
158-
162+
159163
p <- ggplot(data, aes(
160164
x = Date,
161165
y = !!sym(value),
162166
group = 1
163167
)) +
164168
geom_bar(stat = "identity", colour = .ColorBars)
165-
169+
166170
if (rollm) {
167171
# use !sym() to parse rolled.value
168172
message("Add rolled mean for ", value)
@@ -175,10 +179,12 @@ bar_plot_data <- function(data, value, startdate = data$Date[1], rollm = FALSE,
175179
theme_plot()
176180
# add scales
177181
p <- scale_axes(p, date.break)
178-
182+
179183
#add title if present
180184
if (!missing(title))
181185
p <- p + labs(title = title)
182-
p
186+
pp <- p %>%
187+
ggplotly(tooltip = c("x", "y"))
188+
pp
183189
}
184190

renv.lock

+171
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,27 @@
6161
],
6262
"Hash": "45f0398006e83a5b10b72a90663d8d8c"
6363
},
64+
"Rcpp": {
65+
"Package": "Rcpp",
66+
"Version": "1.0.12",
67+
"Source": "Repository",
68+
"Repository": "CRAN",
69+
"Requirements": [
70+
"methods",
71+
"utils"
72+
],
73+
"Hash": "5ea2700d21e038ace58269ecdbeb9ec0"
74+
},
75+
"askpass": {
76+
"Package": "askpass",
77+
"Version": "1.2.0",
78+
"Source": "Repository",
79+
"Repository": "RSPM",
80+
"Requirements": [
81+
"sys"
82+
],
83+
"Hash": "cad6cf7f1d5f6e906700b9d3e718c796"
84+
},
6485
"base64enc": {
6586
"Package": "base64enc",
6687
"Version": "0.1-3",
@@ -173,6 +194,40 @@
173194
],
174195
"Hash": "e8a1e41acf02548751f45c718d55aa6a"
175196
},
197+
"crosstalk": {
198+
"Package": "crosstalk",
199+
"Version": "1.2.1",
200+
"Source": "Repository",
201+
"Repository": "RSPM",
202+
"Requirements": [
203+
"R6",
204+
"htmltools",
205+
"jsonlite",
206+
"lazyeval"
207+
],
208+
"Hash": "ab12c7b080a57475248a30f4db6298c0"
209+
},
210+
"curl": {
211+
"Package": "curl",
212+
"Version": "5.2.1",
213+
"Source": "Repository",
214+
"Repository": "CRAN",
215+
"Requirements": [
216+
"R"
217+
],
218+
"Hash": "411ca2c03b1ce5f548345d2fc2685f7a"
219+
},
220+
"data.table": {
221+
"Package": "data.table",
222+
"Version": "1.15.4",
223+
"Source": "Repository",
224+
"Repository": "RSPM",
225+
"Requirements": [
226+
"R",
227+
"methods"
228+
],
229+
"Hash": "8ee9ac56ef633d0c7cab8b2ca87d683e"
230+
},
176231
"desc": {
177232
"Package": "desc",
178233
"Version": "1.4.3",
@@ -396,6 +451,36 @@
396451
],
397452
"Hash": "2d7b3857980e0e0d0a1fd6f11928ab0f"
398453
},
454+
"htmlwidgets": {
455+
"Package": "htmlwidgets",
456+
"Version": "1.6.4",
457+
"Source": "Repository",
458+
"Repository": "RSPM",
459+
"Requirements": [
460+
"grDevices",
461+
"htmltools",
462+
"jsonlite",
463+
"knitr",
464+
"rmarkdown",
465+
"yaml"
466+
],
467+
"Hash": "04291cc45198225444a397606810ac37"
468+
},
469+
"httr": {
470+
"Package": "httr",
471+
"Version": "1.4.7",
472+
"Source": "Repository",
473+
"Repository": "RSPM",
474+
"Requirements": [
475+
"R",
476+
"R6",
477+
"curl",
478+
"jsonlite",
479+
"mime",
480+
"openssl"
481+
],
482+
"Hash": "ac107251d9d9fd72f0ca8049988f1d7f"
483+
},
399484
"isoband": {
400485
"Package": "isoband",
401486
"Version": "0.2.7",
@@ -454,6 +539,17 @@
454539
],
455540
"Hash": "b64ec208ac5bc1852b285f665d6368b3"
456541
},
542+
"later": {
543+
"Package": "later",
544+
"Version": "1.3.2",
545+
"Source": "Repository",
546+
"Repository": "CRAN",
547+
"Requirements": [
548+
"Rcpp",
549+
"rlang"
550+
],
551+
"Hash": "a3e051d405326b8b0012377434c62b37"
552+
},
457553
"lattice": {
458554
"Package": "lattice",
459555
"Version": "0.22-6",
@@ -469,6 +565,16 @@
469565
],
470566
"Hash": "cc5ac1ba4c238c7ca9fa6a87ca11a7e2"
471567
},
568+
"lazyeval": {
569+
"Package": "lazyeval",
570+
"Version": "0.2.2",
571+
"Source": "Repository",
572+
"Repository": "RSPM",
573+
"Requirements": [
574+
"R"
575+
],
576+
"Hash": "d908914ae53b04d4c0c0fd72ecc35370"
577+
},
472578
"lifecycle": {
473579
"Package": "lifecycle",
474580
"Version": "1.0.4",
@@ -568,6 +674,16 @@
568674
],
569675
"Hash": "a623a2239e642806158bc4dc3f51565d"
570676
},
677+
"openssl": {
678+
"Package": "openssl",
679+
"Version": "2.1.2",
680+
"Source": "Repository",
681+
"Repository": "CRAN",
682+
"Requirements": [
683+
"askpass"
684+
],
685+
"Hash": "ea2475b073243d9d338aa8f086ce973e"
686+
},
571687
"pillar": {
572688
"Package": "pillar",
573689
"Version": "1.9.0",
@@ -631,6 +747,38 @@
631747
],
632748
"Hash": "876c618df5ae610be84356d5d7a5d124"
633749
},
750+
"plotly": {
751+
"Package": "plotly",
752+
"Version": "4.10.4",
753+
"Source": "Repository",
754+
"Repository": "RSPM",
755+
"Requirements": [
756+
"R",
757+
"RColorBrewer",
758+
"base64enc",
759+
"crosstalk",
760+
"data.table",
761+
"digest",
762+
"dplyr",
763+
"ggplot2",
764+
"htmltools",
765+
"htmlwidgets",
766+
"httr",
767+
"jsonlite",
768+
"lazyeval",
769+
"magrittr",
770+
"promises",
771+
"purrr",
772+
"rlang",
773+
"scales",
774+
"tibble",
775+
"tidyr",
776+
"tools",
777+
"vctrs",
778+
"viridisLite"
779+
],
780+
"Hash": "a1ac5c03ad5ad12b9d1597e00e23c3dd"
781+
},
634782
"praise": {
635783
"Package": "praise",
636784
"Version": "1.0.0",
@@ -651,6 +799,22 @@
651799
],
652800
"Hash": "0c90a7d71988856bad2a2a45dd871bb9"
653801
},
802+
"promises": {
803+
"Package": "promises",
804+
"Version": "1.3.0",
805+
"Source": "Repository",
806+
"Repository": "CRAN",
807+
"Requirements": [
808+
"R6",
809+
"Rcpp",
810+
"fastmap",
811+
"later",
812+
"magrittr",
813+
"rlang",
814+
"stats"
815+
],
816+
"Hash": "434cd5388a3979e74be5c219bcd6e77d"
817+
},
654818
"ps": {
655819
"Package": "ps",
656820
"Version": "1.7.6",
@@ -815,6 +979,13 @@
815979
],
816980
"Hash": "960e2ae9e09656611e0b8214ad543207"
817981
},
982+
"sys": {
983+
"Package": "sys",
984+
"Version": "3.4.2",
985+
"Source": "Repository",
986+
"Repository": "CRAN",
987+
"Hash": "3a1be13d68d47a8cd0bfd74739ca1555"
988+
},
818989
"testthat": {
819990
"Package": "testthat",
820991
"Version": "3.2.1.1",

tests/testthat/test-plots.R

+8-8
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ data <- process_data(df)
88
test_that("plot works", {
99
pp <- line_plot_data(data, "Daily.Active")
1010

11-
expect_equal(class(pp), c("gg","ggplot"),
11+
expect_equal(class(pp), c("plotly", "htmlwidget"),
1212
label = "wrong plot class")
13-
expect_equal(pp$data, data, label =
14-
"data are different from input")
15-
13+
# expect_equal(pp$data, data, label =
14+
# "data are different from input")
15+
1616
pp <- bar_plot_data(data, "Daily.Active")
17-
18-
expect_equal(class(pp), c("gg","ggplot"),
17+
18+
expect_equal(class(pp), c("plotly", "htmlwidget"),
1919
label = "wrong plot class")
20-
expect_equal(pp$data, data,
21-
label = "data are different from input")
20+
# expect_equal(pp$data, data,
21+
# label = "data are different from input")
2222
})

0 commit comments

Comments
 (0)