Skip to content

Commit

Permalink
added example data, modified functions to work independently with exa…
Browse files Browse the repository at this point in the history
…mple data
  • Loading branch information
rubenpp7 committed Feb 18, 2021
1 parent 42d086f commit 8e66709
Show file tree
Hide file tree
Showing 42 changed files with 673 additions and 578 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
.RData
.Ruserdata
/data-raw
/data
/data-RB
5 changes: 4 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.1.1
Imports: dplyr,
Imports: dplyr,
ggplot2,
googlesheets4,
leaflet,
Expand All @@ -26,3 +26,6 @@ Imports: dplyr,
htmltools
Depends:
R (>= 2.10)
Suggests:
testthat (>= 3.0.0)
Config/testthat/edition: 3
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ export(divesite_depths)
export(divetypes)
export(divetypes_platform)
export(divewatch)
export(example_data)
export(logbook_highlights)
export(logbook_map)
export(logged_depths)
export(prep_data)
export(test_data)
import(dplyr)
import(forcats)
import(ggplot2)
Expand Down
16 changes: 13 additions & 3 deletions R/cum_dives.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,19 @@



cum_dives <- function(){

load("data/scuba_map.RData")
cum_dives <- function(path = getwd()){

if(dir.exists(paste0(path, "/divewatchr_data"))){

load('divewatchr_data/scuba_map.RData')
}

# } else {
#
# load('data/scuba_map.RData')
# }


scuba_map_cum <- scuba_map %>% mutate(cum_dives = seq(1, nrow(scuba_map)))

ggplot(scuba_map_cum,
Expand Down
8 changes: 5 additions & 3 deletions R/divecount_reg.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@

#.........................................................

divecount_reg <- function (){
divecount_reg <- function (path = getwd()){

# Plot dives per country and region
load("data/scuba_clean.RData")
if(dir.exists(paste0(path, "/divewatchr_data"))){

load('divewatchr_data/scuba_clean.RData')
}

ggplot(scuba_clean, aes(x = country, fill = paste0(region, ", " ,country))) +
geom_bar(alpha = 0.7, position = "dodge2") +
Expand Down
9 changes: 6 additions & 3 deletions R/divesite_depths.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@

#.........................................................

divesite_depths <- function (toofew = 1){

load("data/scuba_map.RData")
divesite_depths <- function (toofew = 1, path = getwd()){

if(dir.exists(paste0(path, "/divewatchr_data"))){

load('divewatchr_data/scuba_map.RData')
}

# Drop locations where there is only 1 dive since the point of this plot is showing variation
y <- scuba_map %>% filter (locationID %in% (scuba_map %>%
Expand Down
7 changes: 5 additions & 2 deletions R/divetypes.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@

#.........................................................

divetypes <- function (n.other = 4){
divetypes <- function (n.other = 4, path = getwd()){

load("data/scuba_clean.RData")
if(dir.exists(paste0(path, "/divewatchr_data"))){

load('divewatchr_data/scuba_clean.RData')
}
# Plot platformTypes
types <- count(scuba_clean, diveType, diveClass) %>%
mutate(diveType = ifelse(n < n.other, "Other", diveType),
Expand Down
9 changes: 6 additions & 3 deletions R/divetypes_platform.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@

#.........................................................

divetypes_platform <- function (){

load("data/scuba_clean.RData")
divetypes_platform <- function (path = getwd()){

if(dir.exists(paste0(path, "/divewatchr_data"))){

load('divewatchr_data/scuba_clean.RData')
}
# Plot platformTypes
ggplot(scuba_clean, aes(x = platformType, fill = paste0(region, ", " ,country))) +
geom_bar(alpha = 0.7, position = "dodge2") +
Expand Down
32 changes: 16 additions & 16 deletions R/test_data.R → R/example_data.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#' Creates a fake dataset
#' Creates a example dataset
#'
#' Creates a fake dataset with the basic data to perform the visualizations of the package
#' Creates a example dataset with the basic data to perform the visualizations of the package
#'
#' This function creates a model dataset with the structure
#' This function creates an example dataset with the structure
#' needed to perform the visualization functions from the divewatchr package.
#' It can be used to test the other functions and to show the user how the data must look like.
#' It can be used to run the other functions and to show the user how the data must look like.
#' The output dataset must be copypasted in a google sheets spreadsheet and the user
#' needs to make sure that the data is formatted as character/text
#'
Expand All @@ -15,14 +15,14 @@
#' @import dplyr
#'
#' @export
#' @return 2 csv files with fake data.
#' @return 4 csv files with example data.
#' @examples
#' test_data()
#' example_data()


test_data <- function(path = getwd()){
example_data <- function(path = getwd()){

test_data_logbook <- data.frame (eventDate = sample(seq(as.Date('1999/01/01'),
example_data_logbook <- data.frame (eventDate = sample(seq(as.Date('1999/01/01'),
as.Date('2020/01/01'),
by="day"), 500),
eventTime = NA,
Expand Down Expand Up @@ -83,7 +83,7 @@ test_data_logbook <- data.frame (eventDate = sample(seq(as.Date('1999/01/01'),



test_data_coordinates <- data.frame (locationID = c("Piscina ZOEA" ,
example_data_coordinates <- data.frame (locationID = c("Piscina ZOEA" ,
"Marina del Este" ,
"La Cueva de la Virgen" ,
"Chocolate Island" ,
Expand Down Expand Up @@ -180,7 +180,7 @@ test_data_coordinates <- data.frame (locationID = c("Piscina ZOEA" ,
caveType = NA)


test_data_divetypes <- data.frame (diveType = c("Advanced Open Water Diver Course" ,
example_data_divetypes <- data.frame (diveType = c("Advanced Open Water Diver Course" ,
"Cleaning Dive Leading" ,
"PADI AOWD Assistance" ,
"PADI DSD Assistance" ,
Expand Down Expand Up @@ -227,7 +227,7 @@ test_data_divetypes <- data.frame (diveType = c("Advanced Open Water Diver Cours
"Training"))


test_data_certifications <- data.frame (diverID = c("XXXXXX",
example_data_certifications <- data.frame (diverID = c("XXXXXX",
"XXXXXX",
"XXXXXX",
"XXXXXX"
Expand All @@ -254,9 +254,9 @@ test_data_certifications <- data.frame (diverID = c("XXXXXX",



if(!dir.exists(paste0(path, "/test_data"))) {dir.create("test_data")}
write.csv(test_data_logbook, paste0(path, "/test_data/logbook.csv"), row.names = FALSE, na = "")
write.csv(test_data_coordinates, paste0(path, "/test_data/coordinates.csv"), row.names = FALSE, na = "")
write.csv(test_data_divetypes, paste0(path, "/test_data/divetypes.csv"), row.names = FALSE, na = "")
write.csv(test_data_certifications, paste0(path, "/test_data/certifications.csv"), row.names = FALSE, na = "")
if(!dir.exists(paste0(path, "/data-raw"))) {dir.create("data-raw")}
write.csv(example_data_logbook, paste0(path, "/data-raw/logbook.csv"), row.names = FALSE, na = "")
write.csv(example_data_coordinates, paste0(path, "/data-raw/coordinates.csv"), row.names = FALSE, na = "")
write.csv(example_data_divetypes, paste0(path, "/data-raw/divetypes.csv"), row.names = FALSE, na = "")
write.csv(example_data_certifications, paste0(path, "/data-raw/certifications.csv"), row.names = FALSE, na = "")
}
14 changes: 12 additions & 2 deletions R/logbook_highlights.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,19 @@

#.........................................................

logbook_highlights <- function(){
logbook_highlights <- function(path = getwd()){

if(dir.exists(paste0(path, "/divewatchr_data"))){

load('divewatchr_data/scuba_clean.RData')
}

# } else {
#
# load('data/scuba_clean.RData')
# }


load('data/scuba_clean.RData')

highlights <- gather(data.frame("Number_of_dives" = as.character(nrow(scuba_clean)),
"Number_of_dive_sites" = paste0(nrow(distinct(select(scuba_clean, locationID))),
Expand Down
11 changes: 7 additions & 4 deletions R/logbook_map.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@

#.........................................................

logbook_map <- function (){

load("data/scuba_map.RData")
load("data/scuba_clean.RData")
logbook_map <- function (path = getwd()){

if(dir.exists(paste0(path, "/divewatchr_data"))){

load('divewatchr_data/scuba_clean.RData')
load('divewatchr_data/scuba_map.RData')
}
### MAKING MAP
#--------------------

Expand Down
9 changes: 6 additions & 3 deletions R/logged_depths.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@
#-----------------------------------------------------------------------------------------------------


logged_depths <- function (){

load("data/scuba_map.RData")
logged_depths <- function (path = getwd()){

if(dir.exists(paste0(path, "/divewatchr_data"))){

load('divewatchr_data/scuba_map.RData')
}
# The problem of making the previous function is that scuba_map does not get generated

# Plot date against max depths https://www.neonscience.org/dc-time-series-plot-ggplot-r
Expand Down
25 changes: 16 additions & 9 deletions R/prep_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ if(!is.na(data)){
(scuba_typ <- read_sheet(data, sheet = "divetypes", na = ""))
(scuba_cert <- read_sheet(data, sheet = "certifications", na = ""))
} else {
test_data()
example_data() # not necessary this line because data will be a permanent shared folder and downloadable -- see later
# From the test_data (in case sheets don't work)
(scuba_log <- read.csv(paste0(path, "/test_data/logbook.csv") ))
(scuba_geo <- read.csv(paste0(path, "/test_data/coordinates.csv") ))
(scuba_typ <- read.csv(paste0(path, "/test_data/divetypes.csv") ))
(scuba_cert <- read.csv(paste0(path, "/test_data/certifications.csv") ))
(scuba_log <- read.csv(paste0(path, "/data-raw/logbook.csv") ))
(scuba_geo <- read.csv(paste0(path, "/data-raw/coordinates.csv") ))
(scuba_typ <- read.csv(paste0(path, "/data-raw/divetypes.csv") ))
(scuba_cert <- read.csv(paste0(path, "/data-raw/certifications.csv") ))
}
#.........................................................
### DATA PROCESSING
Expand Down Expand Up @@ -98,10 +98,17 @@ print(st_crs(scuba_map))
scuba_cert <- scuba_cert %>% mutate(certificationDate = as.character(certificationDate))


if(!dir.exists(paste0(path, "/data"))) {dir.create("data")}
save(scuba_map, file = paste0(path, "/data/scuba_map.RData"))
save(scuba_clean, file = paste0(path, "/data/scuba_clean.RData"))
save(scuba_cert, file = paste0(path, "/data/scuba_cert.RData"))
if(!is.na(data)){
if(!dir.exists(paste0(path, "/divewatchr_data"))) {dir.create("divewatchr_data")}
save(scuba_map, file = paste0(path, "/divewatchr_data/scuba_map.RData"))
save(scuba_clean, file = paste0(path, "/divewatchr_data/scuba_clean.RData"))
save(scuba_cert, file = paste0(path, "/divewatchr_data/scuba_cert.RData"))
} else {
if(!dir.exists(paste0(path, "/data"))) {dir.create("data")}
save(scuba_map, file = paste0(path, "/data/scuba_map.RData"))
save(scuba_clean, file = paste0(path, "/data/scuba_clean.RData"))
save(scuba_cert, file = paste0(path, "/data/scuba_cert.RData"))
}

#save(scuba_map, file = paste0(path, "/data/scuba_map.rda"))
#save(scuba_clean, file = paste0(path, "/data/scuba_clean.rda"))
Expand Down
Binary file added data-original/TSD.xls.xlsx
Binary file not shown.
Binary file not shown.
Binary file added data-original/ZOEA/2018-08.xlsx
Binary file not shown.
Binary file added data-original/ZOEA/2018-09.xlsx
Binary file not shown.
Binary file added data-original/ZOEA/Planning 2016-07.xlsx
Binary file not shown.
Binary file added data-original/ZOEA/Planning 2016-08.xlsx
Binary file not shown.
Binary file added data-original/ZOEA/Planning 2016-09.xlsx
Binary file not shown.
Binary file added data-original/ZOEA/Planning 2017-07.xlsx
Binary file not shown.
Binary file added data-original/ZOEA/Planning 2017-08.xlsx
Binary file not shown.
Binary file added data-original/ZOEA/Planning 2017-09.xlsx
Binary file not shown.
Binary file added data-original/ZOEA/Planning 2017-09b.xlsx
Binary file not shown.
44 changes: 44 additions & 0 deletions data-original/logbook_data.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
eventID,eventDate,eventTime,locationID,locality,decimalLatitude,decimalLongitude
D-2,2011-08,,La Cresta,"Isla del Fraile, Aguilas (Murcia)",37.407457,-1.548604
D-1,2011-10-21,,"""frente al centro scubasur""",Almunecar (Granada),36.733577,-3.70523
D0,2011-10-21,,"""frente al centro scubasur""",Almunecar (Granada),36.733578,-3.705231
D1,2011-10-22,11:45,Chambao de Joaquin,La Herradura (Granada),36.728883,-3.736961
D2,2011-10-22,14:04,La Piedra del Hombre,La Herradura (Granada),36.725076,-3.736712
D3,2011-10-23,13:08,La Calita,La Herradura (Granada),36.721808,-3.735178
D4,2011-10-23,14:34,La Calita,La Herradura (Granada),36.721808,-3.735178
D5,2012-04-02,12:26,La Cresta,"Isla del Fraile, Aguilas (Murcia)",37.407457,-1.548604
D6,2012-04-03,11:27,Pared Sur,"Isla del Fraile, Aguilas (Murcia)",37.407431,-1.547101
D7,2012-05,,Marina del Este,Almunecar (Granada),36.722489,-3.728296
D8,2012-06,,Marina del Este,Almunecar (Granada),36.72249,-3.728297
D9,2012-06-16,,El Hornillo,Aguilas (Murcia),37.406587,-1.559013
D10,2012-06-16,,La Cabeza del Caballo,Aguilas (Murcia),37.42452,-1.500005
D11,2012-06-16,,El Hornillo,Aguilas (Murcia),37.406587,-1.559013
D12,2012-06-17,,La Cresta,"Isla del Fraile, Aguilas (Murcia)",37.407457,-1.548604
D13,2012-06-17,,El Fontanet,Cabo de Cope (Murcia),37.42451,-1.500005
D14,2012-06-17,,La Cresta,"Isla del Fraile, Aguilas (Murcia)",37.407457,-1.548604
D15,2013-04-22,,Marina del Este,Almunecar (Granada),36.72249,-3.728297
D16,2014-04-09,,Marina del Este,Almunecar (Granada),36.72249,-3.728297
D17,2014-06-19,,El Penhon,Salobrenha (Granada),36.736497,-3.593632
D18,2014-07-28,,Exiles,Sliema (Malta),35.918614,14.498422
D19,2014-07-30,,Exiles,Sliema (Malta),35.918614,14.498422
D20,2017-08-01,,Exiles,Sliema (Malta),35.918614,14.498422
D21,2017-08-02,,Exiles,Sliema (Malta),35.918614,14.498422
D22,2017-08-04,,Exiles,Sliema (Malta),35.918614,14.498422
D23,2017-08-04,,Exiles,Sliema (Malta),35.918614,14.498422
D24,2017-08-05,,Exiles,Sliema (Malta),35.918614,14.498422
D25,2017-08-08,,Exiles,Sliema (Malta),35.918614,14.498422
D26,2017-08-08,,Exiles,Sliema (Malta),35.918614,14.498422
D27,2017-08-11,,"Tug 2, Exiles",Sliema (Malta),35.919331,14.498331
D28,2017-08-12,,"Tug 2, Exiles",Sliema (Malta),35.919331,14.498331
D29,2017-08-13,,Exiles,Sliema (Malta),35.918614,14.498422
D30,2017-08-14,,Exiles,Sliema (Malta),35.918614,14.498422
D31,2018-05-28,,A catedral,Sagres (Portugal),37.006141,-8.92733
D32,2018-05-28,,A catedral,Sagres (Portugal),37.006141,-8.92733
D33,2019-07-06,10:58,Grevelingenmeer,"Zeeland, Netherland",51.747398,3.89119
D34,2019-07-06,14:02,Grevelingenmeer,"Zeeland, Netherland",51.747398,3.89119
D35,2019-08-10,10:36,La Cueva de la Virgen,Cabo de Cope (Murcia),37.424511,-1.500004
D36,2019-08-11,12:16,El Mindanao,Cabo de Cope (Murcia),37.424511,-1.500005
D37,2019-08-15,10:23,La Cresta,"Isla del Fraile, Aguilas (Murcia)",37.407457,-1.548604
D38,2019-08-15,11:58,Pared Sur,"Isla del Fraile, Aguilas (Murcia)",37.407431,-1.547101
D39,2019-10-05,14:30,Oesterdam,"Zeeland, Netherland",51.516707,4.17167
D40,2019-10-05,15.14,Oesterdam,"Zeeland, Netherland",51.516708,4.171671
Binary file added data-original/malapascua-data.xlsx
Binary file not shown.
Binary file added data/scuba_cert.RData
Binary file not shown.
Binary file added data/scuba_clean.RData
Binary file not shown.
Binary file added data/scuba_map.RData
Binary file not shown.
4 changes: 2 additions & 2 deletions files/overview.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ knitr::kable(logbook_highlights())
This data frame shows the diving logbook used. Personal information such as eventRemarks are omitted from this data frame

```{r echo=FALSE, rows.print=15}
load('data/scuba_clean.RData')
load('divewatchr_data/scuba_clean.RData')
transmute (scuba_clean, eventDate, locationID, locality, maximumDepth = maximumDepthInMeters, bottomTime, diveType, diveClass, platformType, region, country)
Expand All @@ -154,7 +154,7 @@ transmute (scuba_clean, eventDate, locationID, locality, maximumDepth = maximumD
## Certifications

```{r echo=FALSE, rows.print=15}
load('data/scuba_cert.RData')
load('divewatchr_data/scuba_cert.RData')
knitr::kable(scuba_cert %>% select (-instructorID))
```
Expand Down
2 changes: 1 addition & 1 deletion man/cum_dives.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/divecount_reg.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/divesite_depths.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/divetypes.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 8e66709

Please sign in to comment.