knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

cvera


cvera is an R package with a collection of utility R functions, useful in exploring Irish bTB datasets collated in CVERA.


Installation

You can install the development version of cvera from GitHub with:

# install.packages("devtools")
devtools::install_github("044mj/cvera")

Example

Extract yearly summary data and visualisations of reactor numbers from master_tb dataset.

Read in data:

library(tidyverse)
# if using readr::read_csv() they use first 1000 rows to guess type. 
# If the first 1,000 are missing, it will default to logical. GIF variables are missing in the first 1000
#because it only came in during May 2019 so include col_types for these variables:
master_tb <- read_csv("data/master_tb_24_Mar_2022.csv", 
                          col_types = cols(.default = "?", 
                                           gif_actual_date = col_date(), 
                                           gif_cases = col_number(),
                                           sequence_number = col_character()))

Using all_cases_per_year from cvera package:

library(cvera)
#drop 2022 figures as we only have 3 months worth of data
cases <- all_cases_per_year(master_tb, drop_years = c(2022))

results in

cases_example <- readRDS("data/cases_example.rds")
cases_example

Interactive herd plot:

p <- herd_plot(master_tb, "x1234567") #fake herd
p
knitr::include_graphics("data/herd_plot_figure_2.png") #works in chunk but not when you render
#knitr::include_graphics(path.expand("~/data/historic_gif_eamonn.png"))

Create BD file - summary of all BDs

bd_df <- bd_dataset_fun(master_tb)

Check if BD occured during particular years

bd_df <- bd_during_year(bd_df, years_to_check = c(2005:2006))

Helper function to select core variables

master_tb %>%
 filter(total_reactor_skin > 10) %>%
 core_vars()

Create indicator variable if herd had BD within e.g. 365 days prior to current one

bd_df <- bd_within_time_period(bd_df, 2016, 730)


044mj/cvera documentation built on Feb. 13, 2023, 10:02 p.m.