This repository has been archived by the owner on Jun 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
data_refresh.R
75 lines (58 loc) · 2.27 KB
/
data_refresh.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#' Update the coronavirus Dataset
#' @param silence A boolean, if set to TRUE, will automatically install updates without prompt question, by default set to FALSE
#' @description Update the package datasets on the global environment with the most recent data on the Dev version
#' @details As the CRAN version is being updated every one-two months, the dev version of the package is being updated on a daily bases.
#' This function enables to refresh the package dataset to the most up-to-date data. Changes will be available on the global environment
#' @return A data.frame object
#' @source coronavirus - Johns Hopkins University Center for Systems Science and Engineering (JHU CCSE) Coronavirus \href{https://systems.jhu.edu/research/public-health/ncov/}{website}
#' @export update_dataset
#'
#' @examples
#'\dontrun{
#'
#' # update with a question prompt
#' update_dataset(silence = FALSE)
#'
#'
#' # update without a question prompt
#' update_dataset(silence = TRUE)
#' }
update_dataset <- function(silence = FALSE){
flag <- FALSE
coronavirus_current <- coronavirus::coronavirus
iran_current <- coronavirus::covid_iran
sk_current <- coronavirus::covid_south_korea
coronavirus_git <- utils::read.csv("https://raw.githubusercontent.com/RamiKrispin/coronavirus/master/csv/coronavirus.csv",
stringsAsFactors = FALSE)
coronavirus_git$date <- base::as.Date(coronavirus_git$date)
if(!base::identical(coronavirus_git, coronavirus_current)){
if(base::nrow(coronavirus_git) > base::nrow(coronavirus_current)){
flag <- TRUE
}
}
if(flag){
if(!silence){
q <- base::tolower(base::readline("Updates are available on the coronavirus Dev version, do you want to update? n/Y"))
} else {
q <- "y"
}
if(q == "y" | q == "yes"){
base::tryCatch(
expr = {
devtools::install_github("RamiKrispin/coronavirus")
base::message("The data was refresed, please restart your session to have the new data available")
},
error = function(e){
message('Caught an error!')
print(e)
},
warning = function(w){
message('Caught an warning!')
print(w)
}
)
}
} else {
base::message("No updates are available")
}
}