Skip to content
Snippets Groups Projects
Commit bfe1421a authored by Ben Anderson's avatar Ben Anderson
Browse files

updated various functions & re-built

parent d2722d4d
No related branches found
No related tags found
No related merge requests found
# State required packages
#' @import data.table
#' @import lubridate
#' @import readr
#' Tidy long numbers
#'
#' \code{tidyNum} reformats long numbers to include commas and prevents scientific formats
#'
#' @param number an input number or list
#'
#' @author Ben Anderson, \email{b.anderson@@soton.ac.uk}
#' @export
#'
tidyNum <- function(number) {
format(number, big.mark=",", scientific=FALSE)
}
#' Find the path to Parent Directory
#'
#' Equivalent of \code{findParentDirectory}. Is useful for running a project
#' across multiple computers where the project is stored in different directories.
#'
#' @param Parent the name of the directory to which the function should track back.
#' Should be the root of the GitHub repository
#'
#' @author Mikey Harper, \email{m.harper@@soton.ac.uk}
#' @export
#'
findParentDirectory <- function(Parent){
directory <-getwd()
while(basename(directory) != Parent){
directory <- dirname(directory)
}
return(directory)
}
#' Installs and loads packages
#'
#' \code{myRequiredPackages} checks whether the package is already installed,
#' installing those which are not preinstalled. All the libraries are then load.
#'
#' Especially useful when running on virtual machines where package installation
#' is not persistent (Like UoS sve). It will fail if the packages need to be
#' installed but there is no internet access
#' @param ... A list of packages
#' @param repository The repository to load functions from. Defaults to "https://cran.ma.imperial.ac.uk/"
#' @importFrom utils install.packages
#'
#' @author Luke Blunden, \email{lsb@@soton.ac.uk} (original)
#' @author Michael Harper \email{m.harper@@soton.ac.uk} (revised version)
#' @export
#'
myRequiredPackages <- function(..., repository = "https://cran.rstudio.com"){
packages <- c(...)
# Find if package isn't installed
newPackages <- packages[!(packages %in% utils::installed.packages()[,1])]
# Install if required
if (length(newPackages)){utils::install.packages(newPackages, dependencies = TRUE)}
# Load packages
sapply(packages, require, character.only = TRUE)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment