diff --git a/NAMESPACE b/NAMESPACE index c9134cd..d3bd17c 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -7,6 +7,7 @@ export(Brown2reference) export(Datetime_breaks) export(Datetime_limits) export(aggregate_Datetime) +export(count.difftime) export(create_Time.data) export(cut_Datetime) export(data2reference) diff --git a/NEWS.md b/NEWS.md index e12038f..71ea700 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,8 +1,10 @@ # LightLogR 0.2.1.9000 +* Exports the up to now internal function `count.difftime()` that is the basis for `dominant_epoch()`. But whereas the latter gets only the most common epoch, `count.difftime()` returns a table with the counts of all epochs. This is useful in conjunction with `gap_finder()`, to check the distribution of data intervals. + * Added the `gg_days()` function to visualize multiple days of data in a single plot. Alongside come two helper functions, `Datetime_limits()` and `Datetime_breaks()`, to set the limits and breaks of the x-axis. -* Added the `filter_Datetime_multiple()` function to filter for multiple Datetime ranges depending on certain conditions, e.g. different filter cutoffs for different participants. +* Added the `filter_Datetime_multiple()` function to filter for multiple Datetime ranges depending on certain conditions, e.g. different filter cutoffs for different participants. It wraps around `filter_Datetime()` or `filter_Date()`. * Reworked the internals of the light logger data import functions. They now use a more straightforward function factory approach. For users the only visible change it that device specific functions now have the form `import$device()` instead of the old `import.device()`. diff --git a/R/aaa.r b/R/aaa.r index 14e55c2..e5f6add 100644 --- a/R/aaa.r +++ b/R/aaa.r @@ -1,4 +1,4 @@ -Time <- mEDI <- Time.data <- Datetime <- timestamp <- tz <- Day.data <- `DATE/TIME` <- n <- Datetime.rounded <- id <- sleep.colname.string <- file.name <- Interval <- original.datapoints.fleeting <- MEDI <- State.Brown <- Reference <- Reference.check <- Id <- Start.date.shift <- data <- Shift <- `MELANOPIC EDI` <- State <- group <- End <- Start <- Quant.x <- Quant.y <- is.implicit <- group.indices <- Id2 <- gap.id <- start <- end <- path <- auto.id <- n_max <- manual.id <- NULL +Time <- mEDI <- Time.data <- Datetime <- timestamp <- tz <- Day.data <- `DATE/TIME` <- n <- Datetime.rounded <- id <- sleep.colname.string <- file.name <- Interval <- original.datapoints.fleeting <- MEDI <- State.Brown <- Reference <- Reference.check <- Id <- Start.date.shift <- data <- Shift <- `MELANOPIC EDI` <- State <- group <- End <- Start <- Quant.x <- Quant.y <- is.implicit <- group.indices <- Id2 <- gap.id <- start <- end <- path <- auto.id <- n_max <- manual.id <- silent <- NULL empty_function <- function() { rsconnect::accountInfo() diff --git a/R/gg_day.r b/R/gg_day.r index 4c4d365..29fe019 100644 --- a/R/gg_day.r +++ b/R/gg_day.r @@ -1,9 +1,9 @@ #' Create a simple Time-of-Day plot of light logger data, faceted by Date #' -#' [gg_day()] will create a simple ggplot for every data in a dataset. The result -#' can further be manipulated like any ggplot. This will be sensible to refine -#' styling or guides. +#' [gg_day()] will create a simple ggplot for every data in a dataset. The +#' result can further be manipulated like any ggplot. This will be sensible to +#' refine styling or guides. #' #' Besides plotting, the function creates two new variables from the given #' `Datetime`: @@ -35,9 +35,9 @@ #' @param start.date,end.date Choose an optional start or end date within your #' `dataset`. Expects a `date`, which can also be a `character` that is #' interpretable as a date, e.g., `"2023-06-03"`. If you need a Datetime or -#' want to cut specific times of each day, use the [filter_Datetime()] function. -#' Defaults to `NULL`, which means that the plot starts/ends with the -#' earliest/latest date within the `dataset`. +#' want to cut specific times of each day, use the [filter_Datetime()] +#' function. Defaults to `NULL`, which means that the plot starts/ends with +#' the earliest/latest date within the `dataset`. #' @param scales For [ggplot2::facet_wrap()], should scales be "fixed", "free" #' or free in one dimension ("free_y" is the default). Expects a `character`. #' @param y.scale How should the y-axis be scaled? @@ -45,10 +45,10 @@ #' * `"log10"` would be a straight logarithmic scale, but cannot handle negative values. #' * `"identity"` does nothing (continuous scaling). #' * a transforming function, such as [symlog_trans()] or [scales::identity_trans()], which allow for more control. -#' @param col optional column name that defines separate sets and colors them. -#' Expects anything that works with the layer data [ggplot2::aes()]. The -#' default color palette can be overwritten outside the function (see -#' examples). +#' @param aes_col,aes_fill optional arguments that define separate sets and +#' colors or fills them. Expects anything that works with the layer data +#' [ggplot2::aes()]. The default color palette can be overwritten outside the +#' function (see examples). #' @param x.axis.breaks,y.axis.breaks Where should breaks occur on the x and #' y.axis? Expects a `numeric vector` with all the breaks. If you want to #' activate the default behaviour of [ggplot2], you need to put in @@ -85,7 +85,7 @@ #' x.axis = Datetime, #' y.axis = `MELANOPIC EDI`, #' y.axis.label = "mEDI (lx)", -#' col = Source) +#' aes_col = Source) #' plot #' #' #you can easily overwrite the color scale afterwards @@ -99,7 +99,8 @@ gg_day <- function(dataset, end.date = NULL, x.axis = Datetime, y.axis = MEDI, - col = NULL, + aes_col = NULL, + aes_fill = NULL, group = NULL, geom = "point", scales = "fixed", @@ -149,7 +150,8 @@ gg_day <- function(dataset, ggplot2::geom_ribbon( ggplot2::aes(ymin = 0, ymax = !!y, group = {{ group }}, - col = {{ col }}), + col = {{ aes_col }}, + fill = {{ aes_fill }}), outline.type = "upper", ... ) @@ -209,7 +211,8 @@ gg_day <- function(dataset, eval(geom_function_expr)( ggplot2::aes( group = {{ group }}, - col = {{ col }}, + col = {{ aes_col }}, + fill = {{ aes_fill }}, ), ...) + ribbon + # Scales -------------------------------------------------------------- diff --git a/R/gg_overview.R b/R/gg_overview.R index 1c97399..50ef01f 100644 --- a/R/gg_overview.R +++ b/R/gg_overview.R @@ -109,6 +109,7 @@ gg_overview <- function(dataset, #general information ggplot2::labs(x = "Datetime")+ #theming and styling + ggplot2::scale_x_datetime()+ cowplot::theme_cowplot()+ ggplot2::theme( panel.grid.major = ggplot2::element_line(colour = "grey98"), diff --git a/R/helper.R b/R/helper.R index 804ca4d..9369a79 100644 --- a/R/helper.R +++ b/R/helper.R @@ -38,14 +38,36 @@ is.all.scalar <- function(...) { purrr::every(\(x) length(x) == 1) } -#counts the different time differences per group (in a grouped dataset) +#' Counts the Time differences (epochs) per group (in a grouped dataset) +#' +#' @inheritParams cut_Datetime +#' +#' @return a `tibble` with the number of occurences of each time difference per +#' group +#' @export +#' +#' @examples +#' #get a dataset with irregular intervals +#' filepath <- system.file("extdata/sample_data_LYS.csv", package = "LightLogR") +#' dataset <- import$LYS(filepath) +#' +#' #count.difftime returns the number of occurences of each time difference +#' #and is more comprehensive in terms of a summary than `gap_finder` or +#' #`dominant_epoch` +#' count.difftime(dataset) +#' dominant_epoch(dataset) +#' gap_finder(dataset) +#' +#' #irregular data can be regularized with `aggregate_Datetime` +#' dataset %>% aggregate_Datetime(unit = "15 secs") %>% count.difftime() + count.difftime <- function(dataset, Datetime.colname = Datetime) { dataset %>% dplyr::mutate( difftime = c(NA, diff({{Datetime.colname}}) %>% lubridate::as.duration()) ) %>% tidyr::drop_na(difftime) %>% - dplyr::count(difftime, sort = TRUE) + dplyr::count(difftime = difftime %>% lubridate::as.duration(), sort = TRUE) } #calculate the nth Quantile of time differences per group (in a grouped dataset) diff --git a/R/import_LL.R b/R/import_LL.R index 8fc309b..eee5a14 100644 --- a/R/import_LL.R +++ b/R/import_LL.R @@ -124,6 +124,7 @@ imports <- function(device, auto.id = ".*", manual.id = NULL, locale = readr::default_locale(), + silent = FALSE, ... = ), #function expression @@ -169,7 +170,7 @@ imports <- function(device, dplyr::arrange(Datetime, .by_group = TRUE) #give info about the file - import.info(tmp, !!device, tz, !!ID.colname) + if(!silent) import.info(tmp, !!device, tz, !!ID.colname) #return the file tmp diff --git a/R/symlog_trans.R b/R/symlog_trans.R index f69337d..b04a9e5 100644 --- a/R/symlog_trans.R +++ b/R/symlog_trans.R @@ -23,13 +23,13 @@ #' .default = `MELANOPIC EDI`)) #' #basic application where transformation, breaks and labels are set manually #' dataset %>% -#' gg_day(col = Source) + +#' gg_day(aes_col = Source) + #' ggplot2::scale_y_continuous( #' trans = "symlog") #' #' #the same plot, but with breaks and labels set manually #' dataset %>% -#' gg_day(col = Source) + +#' gg_day(aes_col = Source) + #' ggplot2::scale_y_continuous( #' trans = "symlog", #' breaks = c(-10^(5:0), 0, 10^(0:5)), @@ -38,7 +38,7 @@ #' #setting individual arguments of the symlog function manually allows #' #e.g., to emphasize values smaller than 1 #' dataset %>% -#' gg_day(col = Source) + +#' gg_day(aes_col = Source) + #' ggplot2::scale_y_continuous( #' trans = symlog_trans(thr = 0.01), #' breaks = c(-10^(5:-1), 0, 10^(-1:5)), diff --git a/README.Rmd b/README.Rmd index 9d14770..0d9cee5 100644 --- a/README.Rmd +++ b/README.Rmd @@ -90,7 +90,7 @@ There is a wide range of options to the `gg_day()` function to customize the out ```{r, fig.retina=2} dataset %>% gg_day( - col = MEDI >= 250, scales = "fixed", size = 0.5) + + aes_col = MEDI >= 250, scales = "fixed", size = 0.5) + scale_color_discrete(type = c("orange", "skyblue")) ``` @@ -103,7 +103,7 @@ sample.data.environment %>% gg_day( start.date = "2023-08-18", y.axis = `MELANOPIC EDI`, - col = Source, + aes_col = Source, scales = "fixed", geom = "line") ``` @@ -114,7 +114,7 @@ sample.data.environment %>% gg_day( end.date = "2023-08-15", y.axis = `MELANOPIC EDI`, - col = Source, + aes_col = Source, scales = "fixed", geom = "boxplot", group = interaction(Source, Datetime.rounded)) + diff --git a/README.md b/README.md index 7815636..1fa6e58 100644 --- a/README.md +++ b/README.md @@ -126,7 +126,7 @@ options. You can also override most of the defaults, e.g., for different ``` r dataset %>% gg_day( - col = MEDI >= 250, scales = "fixed", size = 0.5) + + aes_col = MEDI >= 250, scales = "fixed", size = 0.5) + scale_color_discrete(type = c("orange", "skyblue")) #> Scale for colour is already present. #> Adding another scale for colour, which will replace the existing scale. @@ -147,7 +147,7 @@ sample.data.environment %>% gg_day( start.date = "2023-08-18", y.axis = `MELANOPIC EDI`, - col = Source, + aes_col = Source, scales = "fixed", geom = "line") #> Only Dates will be used from start.date and end.date input. If you also want to set Datetimes or Times, consider using the `filter_Datetime()` function instead. @@ -170,7 +170,7 @@ sample.data.environment %>% gg_day( end.date = "2023-08-15", y.axis = `MELANOPIC EDI`, - col = Source, + aes_col = Source, scales = "fixed", geom = "boxplot", group = interaction(Source, Datetime.rounded)) + diff --git a/_pkgdown.yml b/_pkgdown.yml index 4cac854..2c4ab87 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -15,20 +15,29 @@ reference: - import - import.Statechanges - - title: Process + - title: Insight desc: > - This section includes functions to process light logger data, e.g., to - validate and clean data, to filter, cut or aggreagate data, or to join - datasets. + This section includes functions to gain more insight into light logger. + Functions in this section will not return a version of the input dataset, + but rather information based on it. contents: + - count.difftime - dominant_epoch - gapless_Datetimes - - gap_handler - gap_finder + + - title: Validate & Process + desc: > + This section includes functions to process light logger data, e.g., to + validate and clean data, to filter, cut or aggreagate data, or to join + datasets. All of these functions will return a version of the input dataset. + contents: + - gap_handler - cut_Datetime - aggregate_Datetime - create_Time.data - filter_Datetime + - filter_Datetime_multiple - filter_Date - filter_Time - join.datasets @@ -53,7 +62,15 @@ reference: contents: - gg_overview - gg_day + - gg_days + + - title: Helpers + desc: > + This section includes helper functions that are used in the other sections. + contents: - symlog_trans + - Datetime_breaks + - Datetime_limits - title: Datasets desc: > diff --git a/man/count.difftime.Rd b/man/count.difftime.Rd new file mode 100644 index 0000000..a936fd5 --- /dev/null +++ b/man/count.difftime.Rd @@ -0,0 +1,39 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/helper.R +\name{count.difftime} +\alias{count.difftime} +\title{Counts the Time differences (epochs) per group (in a grouped dataset)} +\usage{ +count.difftime(dataset, Datetime.colname = Datetime) +} +\arguments{ +\item{dataset}{A light logger dataset. Expects a \code{dataframe}. If not imported +by \link{LightLogR}, take care to choose a sensible variable for the +\code{Datetime.colname}.} + +\item{Datetime.colname}{column name that contains the datetime. Defaults to +\code{"Datetime"} which is automatically correct for data imported with +\link{LightLogR}. Expects a \code{symbol}. Needs to be part of the \code{dataset}.} +} +\value{ +a \code{tibble} with the number of occurences of each time difference per +group +} +\description{ +Counts the Time differences (epochs) per group (in a grouped dataset) +} +\examples{ +#get a dataset with irregular intervals +filepath <- system.file("extdata/sample_data_LYS.csv", package = "LightLogR") +dataset <- import$LYS(filepath) + +#count.difftime returns the number of occurences of each time difference +#and is more comprehensive in terms of a summary than `gap_finder` or +#`dominant_epoch` +count.difftime(dataset) +dominant_epoch(dataset) +gap_finder(dataset) + +#irregular data can be regularized with `aggregate_Datetime` +dataset \%>\% aggregate_Datetime(unit = "15 secs") \%>\% count.difftime() +} diff --git a/man/gg_day.Rd b/man/gg_day.Rd index 10f5066..e3dbc50 100644 --- a/man/gg_day.Rd +++ b/man/gg_day.Rd @@ -10,7 +10,8 @@ gg_day( end.date = NULL, x.axis = Datetime, y.axis = MEDI, - col = NULL, + aes_col = NULL, + aes_fill = NULL, group = NULL, geom = "point", scales = "fixed", @@ -36,9 +37,9 @@ by \link{LightLogR}, take care to choose a sensible variable for the \code{x.axi \item{start.date, end.date}{Choose an optional start or end date within your \code{dataset}. Expects a \code{date}, which can also be a \code{character} that is interpretable as a date, e.g., \code{"2023-06-03"}. If you need a Datetime or -want to cut specific times of each day, use the \code{\link[=filter_Datetime]{filter_Datetime()}} function. -Defaults to \code{NULL}, which means that the plot starts/ends with the -earliest/latest date within the \code{dataset}.} +want to cut specific times of each day, use the \code{\link[=filter_Datetime]{filter_Datetime()}} +function. Defaults to \code{NULL}, which means that the plot starts/ends with +the earliest/latest date within the \code{dataset}.} \item{x.axis, y.axis}{column name that contains the datetime (x, defaults to \code{"Datetime"} which is automatically correct for data imported with @@ -47,10 +48,10 @@ melanopic EDI, which is a standard measure of stimulus strength for the nonvisual effects of light). Expects a \code{symbol}. Needs to be part of the \code{dataset}.} -\item{col}{optional column name that defines separate sets and colors them. -Expects anything that works with the layer data \code{\link[ggplot2:aes]{ggplot2::aes()}}. The -default color palette can be overwritten outside the function (see -examples).} +\item{aes_col, aes_fill}{optional arguments that define separate sets and +colors or fills them. Expects anything that works with the layer data +\code{\link[ggplot2:aes]{ggplot2::aes()}}. The default color palette can be overwritten outside the +function (see examples).} \item{group}{Optional column name that defines separate sets. Useful for certain geoms like \code{boxplot}.Expects anything that works with the layer @@ -111,9 +112,9 @@ used to adjust to adjust size, linewidth, or linetype.} A ggplot object } \description{ -\code{\link[=gg_day]{gg_day()}} will create a simple ggplot for every data in a dataset. The result -can further be manipulated like any ggplot. This will be sensible to refine -styling or guides. +\code{\link[=gg_day]{gg_day()}} will create a simple ggplot for every data in a dataset. The +result can further be manipulated like any ggplot. This will be sensible to +refine styling or guides. } \details{ Besides plotting, the function creates two new variables from the given @@ -139,7 +140,7 @@ end.date = "2023-08-16", x.axis = Datetime, y.axis = `MELANOPIC EDI`, y.axis.label = "mEDI (lx)", -col = Source) +aes_col = Source) plot #you can easily overwrite the color scale afterwards diff --git a/man/import.Dataset.Rd b/man/import.Dataset.Rd index 033dd88..e1fd94b 100644 --- a/man/import.Dataset.Rd +++ b/man/import.Dataset.Rd @@ -131,7 +131,7 @@ dplyr::slice(1500:1505) \%>\% flextable::flextable() \%>\% flextable::autofit() }\if{html}{\out{}}\if{html}{\out{ -
}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{
}}\if{html}{\out{

}}\if{html}{\out{}}Datetime\if{html}{\out{}}\if{html}{\out{

}}\if{html}{\out{
}}\if{html}{\out{

}}\if{html}{\out{}}TEMPERATURE\if{html}{\out{}}\if{html}{\out{

}}\if{html}{\out{
}}\if{html}{\out{

}}\if{html}{\out{}}LIGHT\if{html}{\out{}}\if{html}{\out{

}}\if{html}{\out{
}}\if{html}{\out{

}}\if{html}{\out{}}MEDI\if{html}{\out{}}\if{html}{\out{

}}\if{html}{\out{
}}\if{html}{\out{

}}\if{html}{\out{}}Id\if{html}{\out{}}\if{html}{\out{

}}\if{html}{\out{
}}\if{html}{\out{

}}\if{html}{\out{}}2023-07-14 13:04:18\if{html}{\out{}}\if{html}{\out{

}}\if{html}{\out{
}}\if{html}{\out{

}}\if{html}{\out{}}29.88\if{html}{\out{}}\if{html}{\out{

}}\if{html}{\out{
}}\if{html}{\out{

}}\if{html}{\out{}}21,847.64\if{html}{\out{}}\if{html}{\out{

}}\if{html}{\out{
}}\if{html}{\out{

}}\if{html}{\out{}}20,660.74\if{html}{\out{}}\if{html}{\out{

}}\if{html}{\out{
}}\if{html}{\out{

}}\if{html}{\out{}}sample_data_ActLumus\if{html}{\out{}}\if{html}{\out{

}}\if{html}{\out{
}}\if{html}{\out{

}}\if{html}{\out{}}2023-07-14 13:05:18\if{html}{\out{}}\if{html}{\out{

}}\if{html}{\out{
}}\if{html}{\out{

}}\if{html}{\out{}}29.88\if{html}{\out{}}\if{html}{\out{

}}\if{html}{\out{
}}\if{html}{\out{

}}\if{html}{\out{}}22,033.77\if{html}{\out{}}\if{html}{\out{

}}\if{html}{\out{
}}\if{html}{\out{

}}\if{html}{\out{}}20,834.91\if{html}{\out{}}\if{html}{\out{

}}\if{html}{\out{
}}\if{html}{\out{

}}\if{html}{\out{}}sample_data_ActLumus\if{html}{\out{}}\if{html}{\out{

}}\if{html}{\out{
}}\if{html}{\out{

}}\if{html}{\out{}}2023-07-14 13:06:18\if{html}{\out{}}\if{html}{\out{

}}\if{html}{\out{
}}\if{html}{\out{

}}\if{html}{\out{}}29.81\if{html}{\out{}}\if{html}{\out{

}}\if{html}{\out{
}}\if{html}{\out{

}}\if{html}{\out{}}21,769.50\if{html}{\out{}}\if{html}{\out{

}}\if{html}{\out{
}}\if{html}{\out{

}}\if{html}{\out{}}20,600.82\if{html}{\out{}}\if{html}{\out{

}}\if{html}{\out{
}}\if{html}{\out{

}}\if{html}{\out{}}sample_data_ActLumus\if{html}{\out{}}\if{html}{\out{

}}\if{html}{\out{
}}\if{html}{\out{

}}\if{html}{\out{}}2023-07-14 13:07:18\if{html}{\out{}}\if{html}{\out{

}}\if{html}{\out{
}}\if{html}{\out{

}}\if{html}{\out{}}29.69\if{html}{\out{}}\if{html}{\out{

}}\if{html}{\out{
}}\if{html}{\out{

}}\if{html}{\out{}}21,177.20\if{html}{\out{}}\if{html}{\out{

}}\if{html}{\out{
}}\if{html}{\out{

}}\if{html}{\out{}}20,061.68\if{html}{\out{}}\if{html}{\out{

}}\if{html}{\out{
}}\if{html}{\out{

}}\if{html}{\out{}}sample_data_ActLumus\if{html}{\out{}}\if{html}{\out{

}}\if{html}{\out{
}}\if{html}{\out{

}}\if{html}{\out{}}2023-07-14 13:08:18\if{html}{\out{}}\if{html}{\out{

}}\if{html}{\out{
}}\if{html}{\out{

}}\if{html}{\out{}}29.44\if{html}{\out{}}\if{html}{\out{

}}\if{html}{\out{
}}\if{html}{\out{

}}\if{html}{\out{}}20,738.98\if{html}{\out{}}\if{html}{\out{

}}\if{html}{\out{
}}\if{html}{\out{

}}\if{html}{\out{}}19,662.14\if{html}{\out{}}\if{html}{\out{

}}\if{html}{\out{
}}\if{html}{\out{

}}\if{html}{\out{}}sample_data_ActLumus\if{html}{\out{}}\if{html}{\out{

}}\if{html}{\out{
}}\if{html}{\out{

}}\if{html}{\out{}}2023-07-14 13:09:18\if{html}{\out{}}\if{html}{\out{

}}\if{html}{\out{
}}\if{html}{\out{

}}\if{html}{\out{}}29.31\if{html}{\out{}}\if{html}{\out{

}}\if{html}{\out{
}}\if{html}{\out{

}}\if{html}{\out{}}20,255.17\if{html}{\out{}}\if{html}{\out{

}}\if{html}{\out{
}}\if{html}{\out{

}}\if{html}{\out{}}19,203.94\if{html}{\out{}}\if{html}{\out{

}}\if{html}{\out{
}}\if{html}{\out{

}}\if{html}{\out{}}sample_data_ActLumus\if{html}{\out{}}\if{html}{\out{

}}\if{html}{\out{
}}\if{html}{\out{
}} +}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{}}\if{html}{\out{
}}\if{html}{\out{

}}\if{html}{\out{}}Datetime\if{html}{\out{}}\if{html}{\out{

}}\if{html}{\out{
}}\if{html}{\out{

}}\if{html}{\out{}}TEMPERATURE\if{html}{\out{}}\if{html}{\out{

}}\if{html}{\out{
}}\if{html}{\out{

}}\if{html}{\out{}}LIGHT\if{html}{\out{}}\if{html}{\out{

}}\if{html}{\out{
}}\if{html}{\out{

}}\if{html}{\out{}}MEDI\if{html}{\out{}}\if{html}{\out{

}}\if{html}{\out{
}}\if{html}{\out{

}}\if{html}{\out{}}Id\if{html}{\out{}}\if{html}{\out{

}}\if{html}{\out{
}}\if{html}{\out{

}}\if{html}{\out{}}2023-07-14 13:04:18\if{html}{\out{}}\if{html}{\out{

}}\if{html}{\out{
}}\if{html}{\out{

}}\if{html}{\out{}}29.88\if{html}{\out{}}\if{html}{\out{

}}\if{html}{\out{
}}\if{html}{\out{

}}\if{html}{\out{}}21,847.64\if{html}{\out{}}\if{html}{\out{

}}\if{html}{\out{
}}\if{html}{\out{

}}\if{html}{\out{}}20,660.74\if{html}{\out{}}\if{html}{\out{

}}\if{html}{\out{
}}\if{html}{\out{

}}\if{html}{\out{}}sample_data_ActLumus\if{html}{\out{}}\if{html}{\out{

}}\if{html}{\out{
}}\if{html}{\out{

}}\if{html}{\out{}}2023-07-14 13:05:18\if{html}{\out{}}\if{html}{\out{

}}\if{html}{\out{
}}\if{html}{\out{

}}\if{html}{\out{}}29.88\if{html}{\out{}}\if{html}{\out{

}}\if{html}{\out{
}}\if{html}{\out{

}}\if{html}{\out{}}22,033.77\if{html}{\out{}}\if{html}{\out{

}}\if{html}{\out{
}}\if{html}{\out{

}}\if{html}{\out{}}20,834.91\if{html}{\out{}}\if{html}{\out{

}}\if{html}{\out{
}}\if{html}{\out{

}}\if{html}{\out{}}sample_data_ActLumus\if{html}{\out{}}\if{html}{\out{

}}\if{html}{\out{
}}\if{html}{\out{

}}\if{html}{\out{}}2023-07-14 13:06:18\if{html}{\out{}}\if{html}{\out{

}}\if{html}{\out{
}}\if{html}{\out{

}}\if{html}{\out{}}29.81\if{html}{\out{}}\if{html}{\out{

}}\if{html}{\out{
}}\if{html}{\out{

}}\if{html}{\out{}}21,769.50\if{html}{\out{}}\if{html}{\out{

}}\if{html}{\out{
}}\if{html}{\out{

}}\if{html}{\out{}}20,600.82\if{html}{\out{}}\if{html}{\out{

}}\if{html}{\out{
}}\if{html}{\out{

}}\if{html}{\out{}}sample_data_ActLumus\if{html}{\out{}}\if{html}{\out{

}}\if{html}{\out{
}}\if{html}{\out{

}}\if{html}{\out{}}2023-07-14 13:07:18\if{html}{\out{}}\if{html}{\out{

}}\if{html}{\out{
}}\if{html}{\out{

}}\if{html}{\out{}}29.69\if{html}{\out{}}\if{html}{\out{

}}\if{html}{\out{
}}\if{html}{\out{

}}\if{html}{\out{}}21,177.20\if{html}{\out{}}\if{html}{\out{

}}\if{html}{\out{
}}\if{html}{\out{

}}\if{html}{\out{}}20,061.68\if{html}{\out{}}\if{html}{\out{

}}\if{html}{\out{
}}\if{html}{\out{

}}\if{html}{\out{}}sample_data_ActLumus\if{html}{\out{}}\if{html}{\out{

}}\if{html}{\out{
}}\if{html}{\out{

}}\if{html}{\out{}}2023-07-14 13:08:18\if{html}{\out{}}\if{html}{\out{

}}\if{html}{\out{
}}\if{html}{\out{

}}\if{html}{\out{}}29.44\if{html}{\out{}}\if{html}{\out{

}}\if{html}{\out{
}}\if{html}{\out{

}}\if{html}{\out{}}20,738.98\if{html}{\out{}}\if{html}{\out{

}}\if{html}{\out{
}}\if{html}{\out{

}}\if{html}{\out{}}19,662.14\if{html}{\out{}}\if{html}{\out{

}}\if{html}{\out{
}}\if{html}{\out{

}}\if{html}{\out{}}sample_data_ActLumus\if{html}{\out{}}\if{html}{\out{

}}\if{html}{\out{
}}\if{html}{\out{

}}\if{html}{\out{}}2023-07-14 13:09:18\if{html}{\out{}}\if{html}{\out{

}}\if{html}{\out{
}}\if{html}{\out{

}}\if{html}{\out{}}29.31\if{html}{\out{}}\if{html}{\out{

}}\if{html}{\out{
}}\if{html}{\out{

}}\if{html}{\out{}}20,255.17\if{html}{\out{}}\if{html}{\out{

}}\if{html}{\out{
}}\if{html}{\out{

}}\if{html}{\out{}}19,203.94\if{html}{\out{}}\if{html}{\out{

}}\if{html}{\out{
}}\if{html}{\out{

}}\if{html}{\out{}}sample_data_ActLumus\if{html}{\out{}}\if{html}{\out{

}}\if{html}{\out{
}}\if{html}{\out{}} } } diff --git a/man/symlog_trans.Rd b/man/symlog_trans.Rd index 2970722..417e723 100644 --- a/man/symlog_trans.Rd +++ b/man/symlog_trans.Rd @@ -31,13 +31,13 @@ dplyr::mutate(MEDI = dplyr::case_when( .default = `MELANOPIC EDI`)) #basic application where transformation, breaks and labels are set manually dataset \%>\% -gg_day(col = Source) + +gg_day(aes_col = Source) + ggplot2::scale_y_continuous( trans = "symlog") #the same plot, but with breaks and labels set manually dataset \%>\% -gg_day(col = Source) + +gg_day(aes_col = Source) + ggplot2::scale_y_continuous( trans = "symlog", breaks = c(-10^(5:0), 0, 10^(0:5)), @@ -46,7 +46,7 @@ labels = function(x) format(x, scientific = FALSE, big.mark = " ")) #setting individual arguments of the symlog function manually allows #e.g., to emphasize values smaller than 1 dataset \%>\% -gg_day(col = Source) + +gg_day(aes_col = Source) + ggplot2::scale_y_continuous( trans = symlog_trans(thr = 0.01), breaks = c(-10^(5:-1), 0, 10^(-1:5)), diff --git a/tests/testthat/test-helper.R b/tests/testthat/test-helper.R new file mode 100644 index 0000000..2e3ca2c --- /dev/null +++ b/tests/testthat/test-helper.R @@ -0,0 +1,9 @@ +test_that("count.difftime works", { + filepath <- system.file("extdata/sample_data_LYS.csv", package = "LightLogR") + dataset <- import$LYS(filepath, silent = TRUE) + dataset <- count.difftime(dataset) + dataset <- dataset$difftime + expect_equal( + dataset, c("15s", "16s", "17s", "18s") %>% lubridate::as.duration() + ) +}) diff --git a/tests/testthat/test-visualize_helper.R b/tests/testthat/test-visualize_helper.R new file mode 100644 index 0000000..6f7d215 --- /dev/null +++ b/tests/testthat/test-visualize_helper.R @@ -0,0 +1,28 @@ +test_that("Datetime_breaks works", { + dataset <- c("2023-08-15", "2023-08-20") + expect_equal(Datetime_breaks(dataset), + c(1692100800, 1692187200, 1692273600, 1692360000, 1692446400) %>% + lubridate::as_datetime()) + expect_equal(Datetime_breaks(dataset, shift = 0), + c(1692057600, + 1692144000, + 1692230400, + 1692316800, + 1692403200, + 1692489600) %>% lubridate::as_datetime()) + expect_equal(Datetime_breaks(dataset, by = "12 hours"), + c(1692100800, 1692144000, 1692187200, 1692230400, 1692273600, + 1692316800, 1692360000, 1692403200, 1692446400, 1692489600) %>% + lubridate::as_datetime()) +}) + +test_that("Datetime_limits works", { + dataset <- c("2023-08-15", "2023-08-20") + breaks <- Datetime_breaks(dataset) + expect_equal(Datetime_limits(breaks), + c("2023-08-15", "2023-08-20") %>% lubridate::as_datetime()) + expect_equal(Datetime_limits(breaks, start = lubridate::ddays(1)), + c("2023-08-16", "2023-08-20") %>% lubridate::as_datetime()) + expect_equal(Datetime_limits(breaks, length = lubridate::ddays(2)), + c("2023-08-15", "2023-08-18") %>% lubridate::as_datetime()) +})