Title: | Different Functions |
---|---|
Description: | More about what it does (maybe more than one line) |
Authors: | Christoffer Moesgaard Albertsen [aut, cre], Technical University of Denmark [cph] |
Maintainer: | Christoffer Moesgaard Albertsen <[email protected]> |
License: | BSD_2_clause + file LICENSE |
Version: | 1.0.2 |
Built: | 2024-11-16 05:05:18 UTC |
Source: | https://github.com/calbertsen/caMisc |
Add shade to a color name
addShade(name, shade = 0)
addShade(name, shade = 0)
name |
name of the color |
shade |
shade value (between 0 and 1). For zero, the same color is returned. |
a new color name
Christoffer Moesgaard Albertsen
Add tint to a color name
addTint(name, tint = 0)
addTint(name, tint = 0)
name |
name of the color |
tint |
tint value (between 0 and 1). For 0, the same color is returned |
a new color name
Christoffer Moesgaard Albertsen
Add tone to a color name
addTone(name, tone = 0)
addTone(name, tone = 0)
name |
name of the color |
tone |
tone value (between 0 and 1). For 0, the same color is returned. |
a new color name
Christoffer Moesgaard Albertsen
Add alpha value to a color name
addTrans(name, alpha = 1)
addTrans(name, alpha = 1)
name |
name of the color |
alpha |
alpha value (between 0 and 1) |
a new color name
Christoffer Moesgaard Albertsen
Draw figure axis inside plot
axisInside(side)
axisInside(side)
side |
side of plot to draw on |
Nothing, but plots as side effect
Christoffer Moesgaard Albertsen
Beanplot of something
beanplot(x, ...)
beanplot(x, ...)
x |
Some object |
... |
Other arguments |
Creates a plot
Christoffer Moesgaard Albertsen
Add text with background to plot
bgtext( x, y, labels, ..., cex = 1, font = NULL, bg = "white", bgex = 1, border = NA )
bgtext( x, y, labels, ..., cex = 1, font = NULL, bg = "white", bgex = 1, border = NA )
x |
x-coordinate |
y |
y-coordinate |
labels |
label to add |
... |
arguments passed to text |
cex |
size of text |
font |
font of text |
bg |
background color |
bgex |
background extend factor |
border |
border color of background |
Christoffer Moesgaard Albertsen
Download and build an R package from GitHub
buildFromGithub( repo, ref, subdir = NULL, buildArgs = c("--no-build-vignettes") )
buildFromGithub( repo, ref, subdir = NULL, buildArgs = c("--no-build-vignettes") )
repo |
GitHub user and repository separated by / |
ref |
Reference to commit or branch. Default is master |
subdir |
Path to subdir containing the package. Should be NULL if the package is in the top directory |
buildArgs |
Character vector of arguments passed to R CMD build. Default is "–no-build-vignettes" |
Nothing
Christoffer Moesgaard Albertsen
Collapse vector to string
collapse( x, collap = c(rep(", ", length(x) - 2), ifelse(length(x) > 2, ", and ", " and ")) )
collapse( x, collap = c(rep(", ", length(x) - 2), ifelse(length(x) > 2, ", and ", " and ")) )
x |
vector of values |
collap |
rule for collapsing |
a string
Christoffer Moesgaard Albertsen
Convert number to display text
displayNum( x, capitalize = FALSE, big.mark = ",", decimal.mark = ".", small.mark = "", digits = 0 )
displayNum( x, capitalize = FALSE, big.mark = ",", decimal.mark = ".", small.mark = "", digits = 0 )
x |
number |
capitalize |
Capitalize first letter? |
LaTeX code for the fraction
Text representation of number
DTU color palette
dtucols(x)
dtucols(x)
x |
name of colors to return |
color codes
Christoffer Moesgaard Albertsen
Format for converting from R Markdown to a DZSlides presentation.
dzslides_presentation( incremental = FALSE, fig_width = 8, fig_height = 6, fig_retina = if (!fig_caption) 2, fig_caption = FALSE, dev = "png", smart = TRUE, self_contained = TRUE, highlight = "default", mathjax = "default", template = "default", css = NULL, includes = NULL, keep_md = FALSE, lib_dir = NULL, md_extensions = NULL, pandoc_args = NULL, ... )
dzslides_presentation( incremental = FALSE, fig_width = 8, fig_height = 6, fig_retina = if (!fig_caption) 2, fig_caption = FALSE, dev = "png", smart = TRUE, self_contained = TRUE, highlight = "default", mathjax = "default", template = "default", css = NULL, includes = NULL, keep_md = FALSE, lib_dir = NULL, md_extensions = NULL, pandoc_args = NULL, ... )
incremental |
should lists be incremental? |
fig_width |
figure width |
fig_height |
figure height |
fig_retina |
retina figure? |
fig_caption |
figure caption? |
dev |
figure device |
smart |
smart? |
self_contained |
self contained? |
highlight |
highlighting style |
mathjax |
mathjax |
template |
template path |
css |
extra css |
includes |
extra includes |
keep_md |
keep markdown file? |
lib_dir |
... |
md_extensions |
markdown extensions to use |
pandoc_args |
extra pandoc arguments |
... |
other arguments |
R Markdown output format to pass to render
Christoffer Moesgaard Albertsen
## Not run: library(rmarkdown) # simple invocation render("pres.Rmd", dzslides_presentation()) # specify an option for incremental rendering render("pres.Rmd", dzslides_presentation(incremental = TRUE)) ## End(Not run) ##' @export
## Not run: library(rmarkdown) # simple invocation render("pres.Rmd", dzslides_presentation()) # specify an option for incremental rendering render("pres.Rmd", dzslides_presentation(incremental = TRUE)) ## End(Not run) ##' @export
Small wrapper for formatC to limit text needed
fd(x, digits = 1)
fd(x, digits = 1)
x |
number |
digits |
number of digits |
string
Christoffer Moesgaard Albertsen
Format date with locale
formatDate(x, format = "", locale = Sys.getlocale("LC_TIME"), ...)
formatDate(x, format = "", locale = Sys.getlocale("LC_TIME"), ...)
x |
date |
format |
format to use |
locale |
locale to use |
... |
passed to strftime |
formatted date string
Christoffer Moesgaard Albertsen
Create coverage table from list of gcov objects
gcovTable(x, ...)
gcovTable(x, ...)
x |
list of gcov objects |
... |
additional arguments passed to formatC |
A coverage table
Christoffer Moesgaard Albertsen
Get a pixel matrix from an image file
getPixelMatrix(file, grey = FALSE)
getPixelMatrix(file, grey = FALSE)
file |
Path to image file |
grey |
Should output be greyscale? |
A matrix of pixel values (0-255)
Christoffer Moesgaard Albertsen
Calculate gradient of a function
grad( func, x, h = abs(1e-04 * x) + 1e-04 * (abs(x) < sqrt(.Machine$double.eps/7e-07)), ... )
grad( func, x, h = abs(1e-04 * x) + 1e-04 * (abs(x) < sqrt(.Machine$double.eps/7e-07)), ... )
func |
function |
x |
parameter values |
h |
step size |
... |
passed to func |
gradient vector
Based on https://personal.sron.nl/~pault/data/colourschemes.pdf
greenBlindness(red, green, blue, alpha = 1, names = NULL, maxColorValue = 255)
greenBlindness(red, green, blue, alpha = 1, names = NULL, maxColorValue = 255)
red |
Red RGB value (or color HEX code or name - alpha is ignored) |
green |
Green RGB value |
blue |
Blue RGB value |
alpha |
alpha value to use |
names |
Names for the resulting vector |
maxColorValue |
Maximum color value for red, green, blue |
New colors
Christoffer Moesgaard Albertsen
Plot image from file
imagePlot( x, objectFit = c("fill", "contain", "cover", "none", "scale-down"), halign = c("c", "l", "r"), valign = c("c", "t", "b"), maxWidthPct = 1, maxHeightPct = 1, add = FALSE, noMargin = TRUE, ... )
imagePlot( x, objectFit = c("fill", "contain", "cover", "none", "scale-down"), halign = c("c", "l", "r"), valign = c("c", "t", "b"), maxWidthPct = 1, maxHeightPct = 1, add = FALSE, noMargin = TRUE, ... )
x |
path to image |
objectFit |
How the image should fill the plot: "fill", "contain", "cover", "none","scale-down" |
halign |
Horizontal alignment: c, l, r |
valign |
Vertical alignment: c, t, b |
noMargin |
Plot with oma and mar set to zero |
... |
other arguments |
Plots the image
Christoffer Moesgaard Albertsen
Download, build, and install package dependencies
installDependencies( descriptionPath, buildArgs = c("--no-build-vignettes"), installArgs = c(), dependencies = c("Depends", "Imports", "LinkingTo") )
installDependencies( descriptionPath, buildArgs = c("--no-build-vignettes"), installArgs = c(), dependencies = c("Depends", "Imports", "LinkingTo") )
descriptionPath |
Path to a DESCRIPTION file |
buildArgs |
Character vector of arguments passed to R CMD build. |
installArgs |
Character vector of arguments passed to R CMD INSTALL. |
dependencies |
Character vector of dependency types to install ("Depends","Imports","LinkingTo","Enhances", or "Suggests") |
Nothing
Christoffer Moesgaard Albertsen
Download, build, and install an R package from GitHub
installFromGithub( repo, ref, subdir = NULL, buildArgs = c("--no-build-vignettes"), installArgs = c(), dependencies = c("Depends", "Imports", "LinkingTo"), https = TRUE )
installFromGithub( repo, ref, subdir = NULL, buildArgs = c("--no-build-vignettes"), installArgs = c(), dependencies = c("Depends", "Imports", "LinkingTo"), https = TRUE )
repo |
GitHub user and repository separated by / |
ref |
Reference to commit or branch. Default is master |
subdir |
Path to subdir containing the package. Should be NULL if the package is in the top directory |
buildArgs |
Character vector of arguments passed to R CMD build. |
installArgs |
Character vector of arguments passed to R CMD INSTALL. |
dependencies |
Character vector of dependency types to install ("Depends","Imports","LinkingTo","Enhances", or "Suggests") |
Nothing
Christoffer Moesgaard Albertsen
Calculate jacobian of a function
jacobian( func, x, h = abs(1e-04 * x) + 1e-04 * (abs(x) < sqrt(.Machine$double.eps/7e-07)), ... )
jacobian( func, x, h = abs(1e-04 * x) + 1e-04 * (abs(x) < sqrt(.Machine$double.eps/7e-07)), ... )
func |
function |
x |
parameter values |
h |
step size |
... |
passed to func |
jacobian matrix
Add map legend for choropleth map
makeMapLegend(x, cols, txt)
makeMapLegend(x, cols, txt)
x |
Variable values plotted |
cols |
Colors |
txt |
Title / description |
Christoffer Moesgaard Albertsen
Make a pixel matrix/array square
makeSquare(p, value = 0, asp = 1)
makeSquare(p, value = 0, asp = 1)
p |
Pixel matrix/array |
value |
Value of added pixels |
Christoffer Moesgaard Albertsen
Create a package skeleton
packageSkeleton(pkg, path = file.path("."))
packageSkeleton(pkg, path = file.path("."))
pkg |
Name of the new package |
path |
(existing) Directory of package |
Used for side effects
Christoffer Moesgaard Albertsen
Function to run a bootstrap particle filter for user defined model.
particlefilter(N, T, G, M, F = NULL, envir = .GlobalEnv, seed = NULL)
particlefilter(N, T, G, M, F = NULL, envir = .GlobalEnv, seed = NULL)
N |
Number of particles |
T |
Number of time steps |
G |
Function to simulate hidden states (of dimension p) given previous (See Details) |
M |
Function to calculate log-likelihood of data for a given particle |
F |
Do not use! |
envir |
Environment the functions should be evaluated in (containing data and parameters) |
seed |
Random seed to start the filter |
The G function should be of the form G <- function(t,X) and return a numeric vector
of simulate values from . For
the function will be called as G(1,NULL).
The M function should be of the form M <- function(t, X) and return the density of the observation at time t given the latent state
A list with a p x N x T array X containing the simulated particles (X) and a vector of length T with the negative log-likelihood contribution at each time point.
Christoffer Moesgaard Albertsen [email protected]
## Univariate example env <- new.env() env$pars <- list(sdobs = 0.4, sdstate = 0.3) local({xx <- cumsum(rnorm(100,0,pars$sdstate))},env) local({dat <- xx + rnorm(100,0,pars$sdobs)},env) G <- function(t,X){ if(t == 1){ return(rnorm(1,0,pars$sdstate)) }else{ return(rnorm(1,X,pars$sdstate)) } } M <- function(t,X){ return(dnorm(dat[t],X,pars$sdobs, TRUE)) } pest <- particlefilter(N = 1000, T = 100, G=G,M=M, envir=env, seed=1) ## Not run: plot(env$dat) lines(apply(pest$X[1,,],2,mean),col="red") lines(apply(pest$X[1,,],2,mean) + 2 * apply(pest$X[1,,],2,sd),col="red",lty=2) lines(apply(pest$X[1,,],2,mean) - 2 * apply(pest$X[1,,],2,sd),col="red",lty=2) lines(env$xx) ## End(Not run) ## Bivariate example env <- new.env() env$pars <- list(sdobs = 0.4, sdstate = 0.3) local({xx <- cbind(cumsum(rnorm(100,0,pars$sdstate)), cumsum(rnorm(100,0,pars$sdstate)))},env) local({dat <- xx + matrix(rnorm(2 * 100,0,pars$sdobs),ncol=2)},env) G <- function(t,X){ if(t == 1){ return(rnorm(2,0,pars$sdstate)) }else{ return(rnorm(2,X,pars$sdstate)) } } M <- function(t,X){ return(sum(dnorm(dat[t,],X,pars$sdobs,TRUE))) } pest <- particlefilter(N = 1000, T = 100, G=G,M=M, envir=env, seed=1) ## Not run: layout(cbind(1,c(2,3))) plot(env$dat) lines(env$xx) lines(apply(pest$X,c(3,1),mean),col="red") plot(env$dat[,1]) lines(apply(pest$X[1,,],2,mean),col="red") lines(apply(pest$X[1,,],2,mean) + 2 * apply(pest$X[1,,],2,sd),col="red",lty=2) lines(apply(pest$X[1,,],2,mean) - 2 * apply(pest$X[1,,],2,sd),col="red",lty=2) lines(env$xx[,1]) plot(env$dat[,2]) lines(apply(pest$X[2,,],2,mean),col="red") lines(apply(pest$X[2,,],2,mean) + 2 * apply(pest$X[2,,],2,sd),col="red",lty=2) lines(apply(pest$X[2,,],2,mean) - 2 * apply(pest$X[2,,],2,sd),col="red",lty=2) lines(env$xx[,2]) ## End(Not run)
## Univariate example env <- new.env() env$pars <- list(sdobs = 0.4, sdstate = 0.3) local({xx <- cumsum(rnorm(100,0,pars$sdstate))},env) local({dat <- xx + rnorm(100,0,pars$sdobs)},env) G <- function(t,X){ if(t == 1){ return(rnorm(1,0,pars$sdstate)) }else{ return(rnorm(1,X,pars$sdstate)) } } M <- function(t,X){ return(dnorm(dat[t],X,pars$sdobs, TRUE)) } pest <- particlefilter(N = 1000, T = 100, G=G,M=M, envir=env, seed=1) ## Not run: plot(env$dat) lines(apply(pest$X[1,,],2,mean),col="red") lines(apply(pest$X[1,,],2,mean) + 2 * apply(pest$X[1,,],2,sd),col="red",lty=2) lines(apply(pest$X[1,,],2,mean) - 2 * apply(pest$X[1,,],2,sd),col="red",lty=2) lines(env$xx) ## End(Not run) ## Bivariate example env <- new.env() env$pars <- list(sdobs = 0.4, sdstate = 0.3) local({xx <- cbind(cumsum(rnorm(100,0,pars$sdstate)), cumsum(rnorm(100,0,pars$sdstate)))},env) local({dat <- xx + matrix(rnorm(2 * 100,0,pars$sdobs),ncol=2)},env) G <- function(t,X){ if(t == 1){ return(rnorm(2,0,pars$sdstate)) }else{ return(rnorm(2,X,pars$sdstate)) } } M <- function(t,X){ return(sum(dnorm(dat[t,],X,pars$sdobs,TRUE))) } pest <- particlefilter(N = 1000, T = 100, G=G,M=M, envir=env, seed=1) ## Not run: layout(cbind(1,c(2,3))) plot(env$dat) lines(env$xx) lines(apply(pest$X,c(3,1),mean),col="red") plot(env$dat[,1]) lines(apply(pest$X[1,,],2,mean),col="red") lines(apply(pest$X[1,,],2,mean) + 2 * apply(pest$X[1,,],2,sd),col="red",lty=2) lines(apply(pest$X[1,,],2,mean) - 2 * apply(pest$X[1,,],2,sd),col="red",lty=2) lines(env$xx[,1]) plot(env$dat[,2]) lines(apply(pest$X[2,,],2,mean),col="red") lines(apply(pest$X[2,,],2,mean) + 2 * apply(pest$X[2,,],2,sd),col="red",lty=2) lines(apply(pest$X[2,,],2,mean) - 2 * apply(pest$X[2,,],2,sd),col="red",lty=2) lines(env$xx[,2]) ## End(Not run)
Read content of .gcov file
read_gcov(file)
read_gcov(file)
file |
path to .gcov file |
a gcov object
Christoffer Moesgaard Albertsen
Read valgrind Massif output
read_massif(file, keep_details = FALSE)
read_massif(file, keep_details = FALSE)
file |
file to read |
keep_details |
keep details? |
massif S3 object
Christoffer Moesgaard Albertsen
Calculate solar angles
solarPosition(date, lat, lon)
solarPosition(date, lat, lon)
date |
date (UTC) in the format "YYY-mm-dd HH:MM:SS" |
lat |
latitude of observer |
lon |
longitude of observer |
list of values
Christoffer Moesgaard Albertsen Modified from https://doi.org/10.1016/j.renene.2021.03.047
Print number as (LaTeX) fraction
tofrac(x, dollar = TRUE)
tofrac(x, dollar = TRUE)
x |
number |
dollar |
LaTeX code for the fraction
Christoffer Moesgaard Albertsen
Turn pixel into grey scale
toGreyscale(p)
toGreyscale(p)
p |
Pixel matrix/array |
A grey scale pixel matrix/array
Christoffer Moesgaard Albertsen