├── .Rbuildignore ├── .Rprofile ├── .gitignore ├── DESCRIPTION ├── NAMESPACE ├── NEWS ├── R ├── TFtest.R ├── addAlpha.R ├── addFade.R ├── addRows.R ├── almost.equal.R ├── anhang.R ├── approx2.R ├── around.R ├── berryFunctions-package.R ├── betaPlot.R ├── betaPlotComp.R ├── between.R ├── bmap.R ├── bpairs.R ├── checkFile.R ├── ciBand.R ├── circle.R ├── classify.R ├── climateGraph.R ├── colPoints.R ├── colPointsHist.R ├── colPointsLegend.R ├── combineFiles.R ├── compareDist.R ├── compareFiles.R ├── convertUmlaut.R ├── count.R ├── createFun.R ├── createPres.R ├── dataStr.R ├── distance.R ├── dupes.R ├── exp4p.R ├── expReg.R ├── funSource.R ├── funnelPlot.R ├── getColumn.R ├── getName.R ├── gof.R ├── googleLink2pdf.R ├── groupHist.R ├── headtail.R ├── horizHist.R ├── if.error.R ├── insertRows.R ├── is.error.R ├── l2array.R ├── l2df.R ├── learnVocab.R ├── legendmt.R ├── library2.R ├── lim0.R ├── linLogHist.R ├── linLogTrans.R ├── linReg.R ├── locArrow.R ├── locLine.R ├── locatorRS.R ├── logAxis.R ├── logHist.R ├── logSpaced.R ├── logVals.R ├── lsMem.R ├── lsc.R ├── mReg.R ├── monthAxis.R ├── monthLabs.R ├── movAv.R ├── movAvLines.R ├── na9.R ├── nameSample.R ├── newFilename.R ├── normPlot.R ├── normTest.R ├── normalizePathCP.R ├── openFile.R ├── openPDF.R ├── owa.R ├── packagePath.R ├── pal.R ├── panelDim.R ├── par_sapply.R ├── parallelCode.R ├── pdfpng.R ├── popleaf.R ├── pretty2.R ├── quantileBands.R ├── quantileMean.R ├── rainbow2.R ├── removeSpace.R ├── rescale.R ├── round0.R ├── roundedRect.R ├── runAxis.R ├── runRversions.R ├── runTime.R ├── seasonality.R ├── seqR.R ├── smallPlot.R ├── smoothLines.R ├── sortDF.R ├── spiralDate.R ├── spiralDateAnim.R ├── sumatraInitialize.R ├── sumatraPaths.R ├── superPos.R ├── tableColVal.R ├── testExamples.R ├── textField.R ├── timeAxis.R ├── timer.R ├── tmessage.R ├── traceCall.R ├── truncMessage.R ├── tryStack.R ├── unitHydrograph.R ├── write.tab.R ├── yearPlot.R └── yearSample.R ├── README.md ├── Tests.R ├── cran-comments.md ├── funs.odt ├── inst └── extdata │ ├── Anhang.pdf │ ├── Q_P.txt │ ├── Rlogo.png │ ├── SumatraPDF-settings.txt │ ├── Temp.txt │ ├── calctime_nameSample.txt │ ├── calctime_nameSample2.txt │ ├── camera.pptx │ ├── camera1.jpg │ ├── camera2.png │ ├── ccby.png │ ├── discharge39072.csv │ ├── doublelines.txt │ ├── dupes.ods │ ├── gelman_equation_search.txt │ ├── mRegProblem.txt │ ├── mRegProblem2.txt │ ├── pmedians.txt │ ├── rivers.txt │ ├── solitaire.txt │ ├── sumatrapdfrestrict.ini │ ├── versuch1.txt │ └── versuch2.txt ├── man ├── TFtest.Rd ├── addAlpha.Rd ├── addFade.Rd ├── addRows.Rd ├── almost.equal.Rd ├── anhang.Rd ├── approx2.Rd ├── around.Rd ├── berryFunctions-package.Rd ├── betaPlot.Rd ├── betaPlotComp.Rd ├── between.Rd ├── bmap.Rd ├── bpairs.Rd ├── catPal.Rd ├── checkFile.Rd ├── ciBand.Rd ├── circle.Rd ├── classify.Rd ├── climateGraph.Rd ├── colPoints.Rd ├── colPointsHist.Rd ├── colPointsLegend.Rd ├── combineFiles.Rd ├── compareDist.Rd ├── compareFiles.Rd ├── convertUmlaut.Rd ├── count.Rd ├── createFun.Rd ├── createPres.Rd ├── dataStr.Rd ├── distance.Rd ├── divPal.Rd ├── dupes.Rd ├── exp4p.Rd ├── expReg.Rd ├── funSource.Rd ├── funnelPlot.Rd ├── getColumn.Rd ├── getName.Rd ├── gof.Rd ├── googleLink2pdf.Rd ├── groupHist.Rd ├── headtail.Rd ├── horizHist.Rd ├── if.error.Rd ├── insertRows.Rd ├── is.error.Rd ├── l2array.Rd ├── l2df.Rd ├── learnVocab.Rd ├── legendmt.Rd ├── library2.Rd ├── lim0.Rd ├── linLogHist.Rd ├── linLogTrans.Rd ├── linReg.Rd ├── locArrow.Rd ├── locLine.Rd ├── locatorRS.Rd ├── logAxis.Rd ├── logHist.Rd ├── logSpaced.Rd ├── logVals.Rd ├── lsMem.Rd ├── lsc.Rd ├── mReg.Rd ├── monthAxis.Rd ├── monthLabs.Rd ├── movAv.Rd ├── movAvLines.Rd ├── na9.Rd ├── nameSample.Rd ├── newFilename.Rd ├── normPlot.Rd ├── normTest.Rd ├── normalizePathCP.Rd ├── openFile.Rd ├── openPDF.Rd ├── owa.Rd ├── packagePath.Rd ├── panelDim.Rd ├── par_sapply.Rd ├── parallelCode.Rd ├── pdfpng.Rd ├── popleaf.Rd ├── pretty2.Rd ├── quantileBands.Rd ├── quantileMean.Rd ├── rainbow2.Rd ├── removeSpace.Rd ├── rescale.Rd ├── round0.Rd ├── roundedRect.Rd ├── runAxis.Rd ├── runRversions.Rd ├── runTime.Rd ├── seasonality.Rd ├── seqPal.Rd ├── seqR.Rd ├── showPal.Rd ├── smallPlot.Rd ├── smoothLines.Rd ├── sortDF.Rd ├── spiralDate.Rd ├── spiralDateAnim.Rd ├── sumatraInitialize.Rd ├── sumatraPaths.Rd ├── superPos.Rd ├── tableColVal.Rd ├── testExamples.Rd ├── textField.Rd ├── timeAxis.Rd ├── timer.Rd ├── tmessage.Rd ├── traceCall.Rd ├── truncMessage.Rd ├── tryStack.Rd ├── unitHydrograph.Rd ├── write.tab.Rd ├── yearPlot.Rd └── yearSample.Rd ├── vignettes └── berryFunctions.Rmd └── zz_berryFunctions.Rproj /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^Meta$ 2 | ^doc$ 3 | ^.*\.Rproj$ 4 | ^\.Rproj\.user$ 5 | cran-comments.md 6 | ^revdep$ 7 | Tests.R 8 | funs.odt 9 | ExampleTestLogs 10 | ^CRAN-SUBMISSION$ 11 | -------------------------------------------------------------------------------- /.Rprofile: -------------------------------------------------------------------------------- 1 | try(br::loadPackages(), silent=TRUE) 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | doc 2 | Meta 3 | .Rproj.user 4 | .Rhistory 5 | .RData 6 | ExampleTestLogs 7 | revdep/ 8 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: berryFunctions 2 | Type: Package 3 | Title: Function Collection Related to Plotting and Hydrology 4 | Version: 1.22.10 5 | Date: 2025-02-11 6 | Imports: grDevices, graphics, stats, utils, abind 7 | Suggests: RColorBrewer, pbapply, knitr, rmarkdown, gstat, RCurl, colorspace, 8 | vioplot, spatstat.geom, ade4, nortest, rstudioapi, 9 | leaflet, leaflet.extras, zoo, R.utils 10 | Author: Berry Boessenkool 11 | Maintainer: Berry Boessenkool 12 | Description: Draw horizontal histograms, color scattered points by 3rd dimension, 13 | enhance date- and log-axis plots, zoom in X11 graphics, trace errors and warnings, 14 | use the unit hydrograph in a linear storage cascade, convert lists to data.frames and arrays, 15 | fit multiple functions. 16 | License: GPL (>= 2) 17 | URL: https://github.com/brry/berryFunctions 18 | RoxygenNote: 7.3.2 19 | Encoding: UTF-8 20 | VignetteBuilder: knitr 21 | BugReports: https://github.com/brry/berryFunctions 22 | -------------------------------------------------------------------------------- /R/TFtest.R: -------------------------------------------------------------------------------- 1 | #' Test logical expressions 2 | #' 3 | #' Check if logical expressions return what you expect with a truth table 4 | #' 5 | #' @details This is a nice way to check operator precedence, see \code{\link{Syntax}} 6 | #' 7 | #' @return Truth table as data.frame with TRUE and FALSE (and NA) combinations 8 | #' @author Berry Boessenkool, \email{berry-b@@gmx.de}, Mrz 2016 9 | #' @seealso \code{\link{logical}} 10 | #' @keywords logic 11 | #' @export 12 | #' @examples 13 | #' TFtest(!a & !b) 14 | #' TFtest(!a & !b, a&b, !(a&b)) 15 | #' TFtest(!a & !b | c) 16 | #' TFtest(!a & !b | c, na=FALSE) 17 | #' TFtest(!a) 18 | #' TFtest(a&b|c, (a&b)|c, a&(b|c), na=FALSE) # AND has precedence over OR 19 | #' TFtest(a|b, xor(a,b), na=FALSE) 20 | #' 21 | #' @param \dots Expression(s) with logical operators to be evaluated, 22 | #' with single letters for variables. Each expression is to be separated with a comma 23 | #' @param na Logical: should NAs be included in the truth table? DEFAULT: TRUE 24 | #' 25 | TFtest <- function( 26 | ..., 27 | na=TRUE 28 | ) 29 | { 30 | # expressions as character strings 31 | depsub <- as.list(substitute(list(...))[-1]) 32 | depsub <- sapply(depsub, function(x) deparse(x)) 33 | 34 | # letters in expression 35 | nlets <- sapply(gregexpr("\\<[a-z,A-Z]{1}\\>", depsub), length) 36 | nn <- max(nlets) 37 | 38 | # combinations of T and F in truth table: 39 | TFvalues <- c(TRUE, FALSE, if(na) NA) 40 | out <- expand.grid(rep(list(TFvalues),nn))[,nn:1, drop=FALSE] 41 | colnames(out) <- letters[1:nn] 42 | 43 | # create objects within function: 44 | for(i in 1:nn) assign(letters[i], out[,i]) 45 | 46 | # evaluate the expression(s): 47 | result <- lapply(depsub, function(x) eval(parse(text=x))) 48 | result <- as.data.frame(result) 49 | colnames(result) <- paste("__", depsub) 50 | 51 | # return output: 52 | cbind(out, result) 53 | } 54 | -------------------------------------------------------------------------------- /R/addAlpha.R: -------------------------------------------------------------------------------- 1 | #' Color transparency 2 | #' 3 | #' Make existing colors semi-transparent (add alpha) 4 | #' 5 | #' @param col Vector of color names (\code{\link{colors}}), hexadecimal or integer that can be interpreted by \code{\link{col2rgb}} 6 | #' @param alpha Level of semi-transparency. between 0 (transparent) and 1 (intransparent). Can also be a vector. DEFAULT: 0.3 7 | 8 | #' @return character vector with hexadecimal color codes. 9 | #' @author Berry Boessenkool, \email{berry-b@@gmx.de}, June 2014 Based on suggestion by Mathias Seibert, Dec. 2013 10 | #' @seealso \code{\link{addFade}}, \code{\link{rgb}}, \code{\link{colors}}, \code{\link{col2rgb}} 11 | #' @keywords dplot color 12 | #' @export 13 | #' @importFrom grDevices col2rgb rgb 14 | #' @examples 15 | #' 16 | #' addAlpha("red", c(0.1, 0.3, 0.6, 1)) 17 | #' addAlpha(1:3) 18 | #' addAlpha(1:3, 1:3/3) 19 | #' NewColors <- addAlpha(c("red","blue","yellow","green", "purple"), 0:200/200) 20 | #' plot(runif(1000), col=NewColors, pch=16, cex=2) 21 | #' 22 | #' # use addFade for line segments, because of overlapping dots 23 | #' set.seed(1); x <- cumsum(rnorm(30)) ; y <- x-2 24 | #' plot(x, type="n") 25 | #' segments(x0=1:29,y0=head(x,-1), x1=2:30,y1=x[-1], col=addAlpha(4, 29:0/30), lwd=10) 26 | #' segments(x0=1:29,y0=head(y,-1), x1=2:30,y1=y[-1], col=addFade (4, 29:0/30), lwd=10) 27 | #' 28 | addAlpha <- function( 29 | col, 30 | alpha=0.3 31 | ) 32 | { 33 | if(any(alpha<0 | alpha>1)) stop("alpha must be between 0 and 1, not ", 34 | toString(alpha[alpha<0|alpha>1])) 35 | rgb2 <- function(x) rgb(x[1], x[2], x[3], alpha=alpha) 36 | output <- apply(X=sapply(col,col2rgb)/255, MARGIN=2, FUN=rgb2) 37 | if( length(alpha)==1 | length(col)==1) return(as.vector(output)) else 38 | if( length(alpha) == length(col) ) return(diag(output)) else 39 | warning("col and alpha had different lengths"); return(output) 40 | } 41 | -------------------------------------------------------------------------------- /R/addFade.R: -------------------------------------------------------------------------------- 1 | #' Color fade out 2 | #' 3 | #' Make existing colors fade away to white 4 | #' 5 | #' @param col Vector of color names (\code{\link{colors}}), hexadecimal or integer that can be interpreted by \code{\link{col2rgb}} 6 | #' @param fade Level of fading towards target. between 0 (target) and 1 (col). Can also be a vector. DEFAULT: 0.3 7 | #' @param target Target color that should be faded into. DEFAULT: "white" 8 | #' @param \dots Further arguments passed to \code{\link{colorRamp}} 9 | 10 | #' @return character matrix with hexadecimal color codes. 11 | #' @author Berry Boessenkool, \email{berry-b@@gmx.de}, Feb 2016 12 | #' @seealso \code{\link{addAlpha}}, \code{\link{colorRamp}}, \code{\link{colors}} 13 | #' @keywords dplot color 14 | #' @importFrom grDevices colorRamp rgb 15 | #' @export 16 | #' @examples 17 | #' 18 | #' plot(1:11, pch=16, cex=3, col=addFade(2, 10:0/10)) 19 | #' plot(1:11, pch=16, cex=3, col=addFade(2, 10:0/10, target="blue")) 20 | #' plot(1:11, pch=16, cex=3, col=addFade(2, 10:0/10, target=3:4)) 21 | #' plot(1:21, pch=16, cex=3, col=addFade(2:3, 10:0/10)) 22 | #' plot(1:21, pch=16, cex=3, col=addFade(2:3, 10:0/10, target=4:5)) 23 | #' NewColors <- addFade(c("red","blue","yellow","green", "purple"), 0:200/200) 24 | #' plot(runif(1000), col=NewColors, pch=16, cex=2) 25 | #' 26 | addFade <- function( 27 | col, 28 | fade=0.3, 29 | target="white", 30 | ... 31 | ) 32 | { 33 | if(any(fade<0 | fade>1)) stop("fade must be between 0 and 1, not ", 34 | toString(fade[fade<0|fade>1])) 35 | cR <- function(fade, col, target) 36 | { 37 | x <- colorRamp(c(col, target))(1-fade) # , ... 38 | x2 <- if (ncol(x) == 4L) 39 | rgb(x[, 1L], x[, 2L], x[, 3L], x[, 4L], maxColorValue = 255) 40 | else rgb(x[, 1L], x[, 2L], x[, 3L], maxColorValue = 255) 41 | x2 42 | } 43 | # output <- sapply(fade, FUN=cR) 44 | output <- sapply(col, FUN=function(co) sapply(fade, FUN=cR, col=co, target=target)) 45 | return(output) 46 | } 47 | -------------------------------------------------------------------------------- /R/addRows.R: -------------------------------------------------------------------------------- 1 | #' Add n rows to a data.frame 2 | #' 3 | #' simple Helper-Function to add n rows to a data.frame. 4 | #' 5 | #' @param df Dataframe object 6 | #' @param n Number of rows to add 7 | #' @param values Values to be used in the new rows. DEFAULT: NA 8 | 9 | #' @return A data.frame 10 | #' @author Berry Boessenkool, \email{berry-b@@gmx.de}, Jan 2014 11 | #' @seealso \code{\link{insertRows}}, \code{\link{sortDF}}, 12 | #' \code{\link{data.frame}}, \code{\link{matrix}}, \code{\link{rbind}} 13 | #' @keywords misc 14 | #' @export 15 | #' @examples 16 | #' 17 | #' MYDF <- data.frame(A=5:3, B=2:4) 18 | #' addRows(MYDF, 3) 19 | #' 20 | addRows <- function( 21 | df, 22 | n, 23 | values=NA) 24 | { 25 | dnew <- data.frame(matrix(values, nrow=n, ncol=ncol(df))) 26 | colnames(dnew) <- colnames(df) 27 | rbind(df, dnew) 28 | } 29 | -------------------------------------------------------------------------------- /R/anhang.R: -------------------------------------------------------------------------------- 1 | #' open the Appendix of Rclick 2 | #' 3 | #' Open the Appendix of my R handbook found online at 4 | #' \url{https://github.com/brry/rclick} 5 | #' 6 | #' @return None, opens pdf in default viewer using \code{\link{system2}} 7 | #' @author Berry Boessenkool, \email{berry-b@@gmx.de}, Jul 2016 8 | #' @seealso \code{\link{funSource}} 9 | #' @export 10 | #' @examples 11 | #' # anhang() # excluded from cran check because of external browser opening policy 12 | #' 13 | anhang <- function() 14 | { 15 | file <- system.file("extdata/Anhang.pdf", package="berryFunctions") 16 | openFile(file) 17 | } 18 | -------------------------------------------------------------------------------- /R/around.R: -------------------------------------------------------------------------------- 1 | #' View values around an index 2 | #' 3 | #' View index rows of a data.frame with n surrounding rows 4 | #' 5 | #' @return Nothing, calls \code{\link{View}} 6 | #' @author Berry Boessenkool, \email{berry-b@@gmx.de}, Nov 2016 7 | #' @seealso \code{\link{sortDF}}, \code{\link{View}} 8 | #' @importFrom utils View 9 | #' @export 10 | #' @examples 11 | #' \dontrun{ ## View should not be used in examples 12 | #' myDF <- data.frame(A=1:30, B=cumsum(rnorm(30))) 13 | #' myDF[c(5,7,23,29),1] <- NA 14 | #' around(myDF, i=is.na(myDF$A)) 15 | #' around(myDF, i=c(11,19), n2=0) 16 | #' } 17 | #' 18 | #' @param x Data.frame 19 | #' @param i Index (logical or integers) 20 | #' @param n1 Number of elements shown before each i. DEFAULT: 2 21 | #' @param n2 Number of elements shown after each i. DEFAULT: n1 22 | #' @param convert Use \code{\link{which}} to get the row numbers? 23 | #' DEFAULT: TRUE if i is boolean 24 | #' 25 | around <- function( 26 | x, 27 | i, 28 | n1=2, 29 | n2=n1, 30 | convert=is.logical(i) 31 | ) 32 | { 33 | if(convert) i <- which(i) 34 | index <- lapply(i, "+", -n1:n2) 35 | index <- unique(unlist(index)) 36 | index <- index[index>0 & index= a & x <= b } to save repeating long x names twice. 4 | #' @return Logical (boolean) vector with TRUE/FALSE values 5 | #' @author Berry Boessenkool, \email{berry-b@@gmx.de}, Aug 2017 6 | #' @seealso \code{\link{findInterval}} 7 | # \code{graphics::\link[graphics]{plot}} 8 | #' @keywords logic 9 | # @importFrom package fun1 fun2 10 | #' @export 11 | #' @examples 12 | #' between(1:10, 4, 8) 13 | #' between(1:10, 4:8) # range as vector 14 | #' between(1:10, 8, 4) # warns about interval 15 | #' 16 | #' data.frame( incl.T=between(1:10, 4, 8), 17 | #' incl.F=between(1:10, 4, 8, incl=FALSE), 18 | #' aincl.F=between(1:10, 4, 8, aincl=FALSE), 19 | #' bincl.F=between(1:10, 4, 8, bincl=FALSE) ) 20 | #' 21 | #' @param x Numerical vector 22 | #' @param a,b Numerical values/vectors specifying the borders of the interval. 23 | #' \code{\link{min}} and \code{max} are used, so they can be a vector. 24 | #' @param incl Logical. Include values on the borders? For x == border, TRUE 25 | #' will be returned. Specify per left and right border separately 26 | #' with the arguments \code{aincl} and \code{bincl}. DEFAULT: TRUE 27 | #' @param aincl,bincl Logical. Include values on left and right border, respectively? 28 | #' DEFAULT: \code{incl} 29 | #' @param quiet Logical. Suppress warning if a>b? DEFAULT: FALSE 30 | #' 31 | between <- function( 32 | x, 33 | a, 34 | b=a, 35 | incl=TRUE, 36 | aincl=incl, 37 | bincl=incl, 38 | quiet=FALSE 39 | ) 40 | { 41 | b <- max(b, na.rm=TRUE) 42 | a <- min(a, na.rm=TRUE) 43 | if(a>b&!quiet) warning("a (",a,") is larger than b (",b, 44 | "), results may differ from intention.") 45 | aa <- if(aincl) x >= a else x > a 46 | bb <- if(bincl) x <= b else x < b 47 | aa & bb 48 | } 49 | -------------------------------------------------------------------------------- /R/bmap.R: -------------------------------------------------------------------------------- 1 | #' @title title 2 | #' @description description 3 | #' @return ReturnValue 4 | #' @author Berry Boessenkool, \email{berry-b@@gmx.de}, Dec 2022 5 | #' @export 6 | #' @examples 7 | #' if(requireNamespace("leaflet", quietly=TRUE) && 8 | #' requireNamespace("leaflet.extras", quietly=TRUE)) 9 | #' bmap() 10 | #' 11 | #' @param x,y,zm passed to \code{leaflet::\link[leaflet]{setView}} 12 | #' @param prov named vector of providers. DEFAULT: NULL (nice selection) 13 | #' @param collapsebg Collapse background (map) layer selection? DEFAULT: TRUE 14 | #' @param \dots Ignored for now 15 | #' 16 | bmap <- function( 17 | x=13.12, 18 | y=52.37, 19 | zm=14, 20 | prov=NULL, 21 | collapsebg=TRUE, 22 | ... 23 | ) 24 | { 25 | if(!requireNamespace("leaflet", quietly=TRUE) || 26 | !requireNamespace("leaflet.extras", quietly=TRUE)) 27 | return(warning("packages leaflet and leaflet.extras must be available for bmap")) 28 | 29 | # create map, add controls: 30 | rmap <- leaflet::leaflet() 31 | rmap <- leaflet.extras::addSearchOSM(rmap, options=leaflet.extras::searchOptions( 32 | autoCollapse=TRUE, minLength=2, hideMarkerOnCollapse=TRUE, zoom=16)) 33 | rmap <- leaflet.extras::addControlGPS(rmap, options=leaflet.extras::gpsOptions( 34 | position="topleft", activate=TRUE, autoCenter=TRUE, maxZoom=16, setView=TRUE)) 35 | rmap <- leaflet::addMeasure(rmap, primaryLengthUnit="meters", primaryAreaUnit="sqmeters", 36 | activeColor="#3D535D", completedColor="#FF0000", position="topleft") 37 | rmap <- leaflet::addScaleBar(rmap, position="topleft") 38 | rmap <- leaflet.extras::addFullscreenControl(rmap) 39 | rmap <- leaflet::setView(rmap, x, y, zoom=zm) 40 | # add background map layer options, from mapview::mapviewGetOption("basemaps") 41 | prov <- c(OSM="OpenStreetMap", 42 | Sat="Esri.WorldImagery", 43 | Topo="OpenTopoMap", 44 | # CycleTF="Thunderforest.OpenCycleMap", 45 | # Night="NASAGIBS.ViirsEarthAtNight2012", 46 | Dark="CartoDB.DarkMatter") 47 | for(pr in names(prov)) rmap <- leaflet::addProviderTiles(rmap, provider=unname(prov[pr]), 48 | group=pr, options=leaflet::providerTileOptions(maxZoom=20)) 49 | rmap <- leaflet::addLayersControl(rmap, baseGroups=names(prov), 50 | options=leaflet::layersControlOptions(collapsed=collapsebg)) 51 | # Output: 52 | return(rmap) 53 | } 54 | -------------------------------------------------------------------------------- /R/bpairs.R: -------------------------------------------------------------------------------- 1 | #' @title customized pairs plot 2 | #' @description pairs plot with cor in the lower panel (can handle NAs), 3 | #' nice hist on the diagonal, nice scatterplot in the upper panel. 4 | #' Based on the examples in pairs. 5 | #' @return invisible NULL 6 | #' @author Berry Boessenkool, \email{berry-b@@gmx.de}, Feb 2025 7 | #' @seealso \code{graphics::\link[graphics]{pairs}} 8 | #' @keywords aplot 9 | #' @importFrom graphics pairs 10 | #' @export 11 | #' @examples 12 | #' bpairs(mtcars[,1:5]) 13 | #' mtcarsNAs <- mtcars[,1:5] 14 | #' mtcarsNAs[2,3] <- NA 15 | #' mtcarsNAs[2:8,4] <- NA 16 | #' bpairs(mtcarsNAs) 17 | #' bpairs(iris) 18 | #' 19 | #' @param df Data.frame. Can contain NAs. Character columns are excluded. 20 | #' @param main Title for the overall graph. DEFAULT: NULL (from input) 21 | #' @param \dots Further arguments passed to \code{\link{pairs}} 22 | #' 23 | bpairs <- function( 24 | df, 25 | main=NULL, 26 | pch=16, 27 | col=addAlpha("blue"), 28 | ... 29 | ) 30 | { 31 | if(is.null(main)) main <- deparse(substitute(df)) 32 | df <- df[!sapply(df, is.character)] 33 | panel.hist <- function(x, ...) 34 | { 35 | usr <- par("usr") 36 | par(usr=c(usr[1:2], 0, 1.5) ) 37 | h <- hist(x, breaks=15, plot=FALSE) 38 | breaks <- h$breaks 39 | nB <- length(breaks) 40 | y <- h$counts 41 | y <- y/max(y) 42 | rect(breaks[-nB], 0, breaks[-1], y, col="salmon") 43 | nNA <- sum(is.na(x)) 44 | if(nNA>0) textField(mean(usr[1:2]), 0.2, paste(nNA, "NA"), fill=addAlpha("white",0.7), cex=1) 45 | axis(1) 46 | box() 47 | } 48 | panel <- function(x, y, pch=pch, col=col, ....) 49 | { 50 | points(x, y, pch=pch, col=col, ...) 51 | r <- abs(cor(x, y, use="complete.obs")) 52 | usr <- par("usr") 53 | text(mean(usr[1:2]), mean(usr[3:4]), round0(r,2,0), cex=exp(r)) 54 | } 55 | pairs(df, panel=panel, diag.panel=panel.hist, lower.panel=NULL, pch=pch, col=col, ...) 56 | title(main=main, outer=TRUE, line=-1) 57 | invisible(NULL) 58 | } 59 | -------------------------------------------------------------------------------- /R/circle.R: -------------------------------------------------------------------------------- 1 | #' Draw circle with a given radius 2 | #' 3 | #' Draws a filled circle with a certain radius (in existing plot's units) using \code{\link{polygon}} and \code{\link{sin}} 4 | #' 5 | #' @note If circles look like ellipsis, use plot(... asp=1) 6 | #' @return data.frame of coordinates, invisible 7 | #' @author Berry Boessenkool, \email{berry-b@@gmx.de}, 2012 8 | #' @seealso \code{\link{symbols}}, \code{\link{polygon}} 9 | #' @keywords aplot 10 | #' @importFrom grDevices rgb 11 | #' @importFrom graphics polygon 12 | #' @export 13 | #' @examples 14 | #' 15 | #' plot(1:20, type="n", asp=1) 16 | #' circle(5,5, r=3) # 1:1 aspect shows they're really circles and not ellipses. 17 | #' circle(15,10, r=4, locnum=12, col=2, border=4, lwd=3) 18 | #' 19 | #' # can not be vectorized: 20 | #' x <- sample(1:20, 15) ; y <- sample(1:20, 15) ; r <- runif(20)*3 21 | #' circle(x,y,r, col=rgb(1,0.5,0,alpha=0.4), border=NA) 22 | #' for(i in 1:15) circle(x[i],y[i],r[i], col=rgb(1,0.5,0,alpha=0.4), border=NA) 23 | #' 24 | #' @param x x coordinate of points, numeric value of length 1 25 | #' @param y y coordinate 26 | #' @param r radius of the circle in units of current plot. 27 | #' Can have two values for an ellipse. 28 | #' @param locnum number of calculated points on the circle (more means smoother but slower). DEFAULT: 100 29 | #' @param \dots further arguments passed to \code{\link{polygon}}, like col, border, lwd 30 | #' 31 | circle <- function( 32 | x, 33 | y, 34 | r, 35 | locnum=100, 36 | ...) 37 | { 38 | # input checking - only one circle can be drawn: 39 | checkinput <- function(i, maxlen=1) 40 | { 41 | n <- deparse(substitute(i)) 42 | if(!is.numeric(i)) stop(n, " must be numeric") 43 | if(length(i) > maxlen) warning("Only the first element of ",n," is used.", call.=FALSE) 44 | i <- rep(i, length.out=maxlen) 45 | i[1:maxlen] 46 | } 47 | x <- checkinput(x) 48 | y <- checkinput(y) 49 | r <- checkinput(r, 2) 50 | locnum <- checkinput(locnum) 51 | # prepare circle line coordinates: 52 | cx <- x+r[1]*cos( seq(0,2*pi,len=locnum) ) 53 | cy <- y+r[2]*sin( seq(0,2*pi,len=locnum) ) 54 | # actually draw it: 55 | polygon(cx, cy, ...) 56 | return(invisible(data.frame(x=cx, y=cy))) 57 | } 58 | -------------------------------------------------------------------------------- /R/compareFiles.R: -------------------------------------------------------------------------------- 1 | #' Compare textfiles for equality 2 | #' 3 | #' Returns the line numbers where two (text)files differ 4 | #' 5 | #' @return Vector of line numbers that differ, result from \code{\link{head}(..., nr)} 6 | #' @author Berry Boessenkool, \email{berry-b@@gmx.de}, Aug 2014 7 | #' @seealso \url{https://text-compare.com/} which I sadly only discovered after writing this function, 8 | #' \code{\link{dupes}} for finding duplicate lines, \code{\link{combineFiles}} 9 | #' @keywords IO file character 10 | #' @importFrom utils head 11 | #' @export 12 | #' @examples 13 | #' 14 | #' filenames <- system.file(paste0("extdata/versuch",1:2,".txt"), package="berryFunctions") 15 | #' compareFiles(filenames[1], filenames[2], warn=FALSE) 16 | #' 17 | #' @param file1,file2 Filenames to be read by \code{\link{readLines}}. 18 | #' @param nr number of results printed. DEFAULT: 20 19 | #' @param startline,endline start and end lines, e.g. to exclude section that is already compared. 20 | #' @param quiet show warnings about file lengths? DEFAULT: FALSE 21 | #' @param \dots further arguments passed to \code{\link{readLines}} 22 | #' 23 | compareFiles <- function( 24 | file1,file2, 25 | nr=20, 26 | startline=1, 27 | endline=length(f1), 28 | quiet=FALSE, 29 | ... 30 | ) 31 | { 32 | checkFile(c(file1,file2)) 33 | f1 <- readLines(file1, ...) 34 | f2 <- readLines(file2, ...) 35 | # truncate: 36 | if(length(f1) > length(f2) ) 37 | { 38 | if(!quiet) warning(length(f1) - length(f2), " lines are discarded at the end of the file ", file1, ", as ", file2, " is shorter.") 39 | f1 <- f1[1:length(f2)] 40 | } 41 | if(length(f2) > length(f1) ) 42 | { 43 | if(!quiet) warning(length(f2) - length(f1), " lines are discarded at the end of the file ", file2, ", as ", file1, " is shorter.") 44 | f2 <- f2[1:length(f1)] 45 | } 46 | # truncate: 47 | f1 <- f1[startline:endline] 48 | f2 <- f2[startline:endline] 49 | # compare 50 | head( which(f1 != f2)+startline-1 , nr) 51 | } 52 | -------------------------------------------------------------------------------- /R/convertUmlaut.R: -------------------------------------------------------------------------------- 1 | #' Convert German Umlaute to ASCII 2 | #' 3 | #' Convert German Umlaute (ae, oe, ue, ss) to ASCII. 4 | #' Conversion happens case sensitive for the first three. 5 | 6 | #' @return Character strings 7 | #' @author Berry Boessenkool, \email{berry-b@@gmx.de}, Oct-Nov 2016 8 | #' @seealso \code{tools::\link[tools]{showNonASCII}}, \code{\link{gsub}}, 9 | #' \code{\link{iconv}(x, to="ASCII//TRANSLIT")} 10 | #' @keywords character 11 | #' @export 12 | #' @examples 13 | #' \dontrun{ 14 | #' link <- paste0("ftp://ftp-cdc.dwd.de/pub/CDC/observations_germany/climate/", 15 | #' "monthly/kl/recent/KL_Monatswerte_Beschreibung_Stationen.txt") 16 | #' weatherstations <- read.fwf(link, widths=c(6,9,10,16,11,8,41,99), skip=3) 17 | #' examples <- trimws(weatherstations[c(153, 509, 587, 2, 651, 851),7]) 18 | #' examples 19 | #' convertUmlaut(examples) # note how lower and upper case is kept 20 | #' } 21 | #' 22 | #' @param x Character string(s) containing German Umlaute 23 | #' 24 | convertUmlaut <- function( 25 | x 26 | ) 27 | { 28 | x <- gsub("\U00E4", "ae", x) 29 | x <- gsub("\U00F6", "oe", x) 30 | x <- gsub("\U00FC", "ue", x) 31 | x <- gsub("\U00DF", "ss", x) 32 | x <- gsub("\U00C4", "Ae", x) 33 | x <- gsub("\U00D6", "Oe", x) 34 | x <- gsub("\U00DC", "Ue", x) 35 | x 36 | } 37 | -------------------------------------------------------------------------------- /R/count.R: -------------------------------------------------------------------------------- 1 | #' @title count string occurrences 2 | #' @description count how often a certain string occurs, summing over a vector 3 | #' @return single integer 4 | #' @author Berry Boessenkool, \email{berry-b@@gmx.de}, Jan 2025 5 | #' @export 6 | #' @examples 7 | #' vec210 <- c("with abc + abc + ab", "also abcde", "no alphabet") 8 | #' vec021 <- c("no alphabet", "this has abcabc + ab", "also abcde") 9 | #' vec000 <- c("this has no", "alphabet", "at all") 10 | #' vec4 <- "this has abc and abcabcabc" 11 | #' stopifnot(count("abc", vec210) == 3) 12 | #' stopifnot(count("abc", vec021) == 3) 13 | #' stopifnot(count("abc", vec000) == 0) 14 | #' stopifnot(count("abc", vec4 ) == 4) 15 | #' 16 | #' @param a character string (can have regex) 17 | #' @param x charstring (vector) 18 | #' @param \dots Further arguments passed to \code{\link{gregexpr}} 19 | #' 20 | count <- function( 21 | pattern, 22 | x, 23 | ... 24 | ) 25 | { 26 | g <- gregexpr(pattern, x, ...) 27 | sum(unlist(g)>0) 28 | } 29 | 30 | -------------------------------------------------------------------------------- /R/distance.R: -------------------------------------------------------------------------------- 1 | #' Distance between points 2 | #' 3 | #' Calculate distance between points on planar surface 4 | #' 5 | #' @details The function is quite simple: \code{sqrt((xref - x)^2 + (yref - y)^2)} 6 | #' 7 | #' @return vector with the distances 8 | #' @author Berry Boessenkool, \email{berry-b@@gmx.de}, 2012 9 | #' @seealso \code{\link[spatstat.geom]{nndist}} in the package \code{spatstat.geom} 10 | #' for distance to nearest neighbour 11 | #' @keywords spatial 12 | #' @export 13 | #' @examples 14 | #' 15 | #' A <- c(3, 9,-1) 16 | #' B <- c(7, -2, 4) 17 | #' plot(A,B) 18 | #' text(A,B, paste0("P",1:3), adj=1.1) 19 | #' points(3,5, col=2, pch=16) 20 | #' segments(3,5, A,B) 21 | #' distance(A,B, 3,5) 22 | #' text(c(3.2,6,1), c(6,1,4), round(distance(A,B, 3,5),2) ) 23 | #' 24 | #' @param x vector with x-coordinate(s) of point(s) 25 | #' @param y ditto for y 26 | #' @param xref single x coordinate of reference point 27 | #' @param yref ditto for y 28 | #' @param along Logical: Should distances be computed along vector \code{(x,y)}? 29 | #' If TRUE, \code{(xref,yref)} are ignored. 30 | #' If both \code{(xref,yref)} are not given, along is set to TRUE. 31 | #' 32 | distance <- function( 33 | x, 34 | y, 35 | xref, 36 | yref, 37 | along=FALSE 38 | ) 39 | { 40 | # input check: 41 | if(missing(xref) & missing(yref)) along <- TRUE 42 | # main function, internally: 43 | dist_int <- function(x,y, xref,yref) sqrt((xref-x)^2 + (yref-y)^2) 44 | if(along) 45 | c(0,sapply(2:length(x), function(i) dist_int(x[i-1],y[i-1], x[i],y[i]))) 46 | else 47 | dist_int(x,y, xref,yref) # normal case 48 | } 49 | -------------------------------------------------------------------------------- /R/getName.R: -------------------------------------------------------------------------------- 1 | #' get the name of an input in nested function calls 2 | #' 3 | #' get the name of an input in nested function calls 4 | #' 5 | #' @return Character string with the name 6 | #' @author \url{https://stackoverflow.com/users/2725969/brodieg} 7 | #' Implementation Berry Boessenkool, \email{berry-b@@gmx.de}, Sep 2016 8 | #' @seealso \url{https://stackoverflow.com/a/26558733}, \code{\link{substitute}} 9 | #' @keywords character IO 10 | #' @importFrom utils head 11 | #' @export 12 | #' @examples 13 | #' # This does not work well: 14 | #' 15 | #' lower <- function(x) deparse(substitute(x)) 16 | #' upper <- function(y) lower(y) 17 | #' lower(pi) # returns "pi", as expected 18 | #' upper(pi) # returns "y". 19 | #' 20 | #' # That's why there is getName: 21 | #' 22 | #' getName(pi) # returns "pi", as expected 23 | #' upper <- function(y) getName(y) 24 | #' upper(pi) # yay! 25 | #' 26 | #' upper("dummy") 27 | #' upper(dummy) # works also for nonexistent objects 28 | #' dummy <- 7 29 | #' upper("dummy") # still stable 30 | #' upper(dummy) # still stable 31 | #' 32 | #' upper(stackloss[1:5,]) 33 | #' 34 | #' upper2 <- function(data) upper(data) 35 | #' upper2("K") 36 | #' upper2(K) 37 | #' 38 | #' # getName only works correctly if x is not an evaluated object: 39 | #' lower2 <- function(inp, assign=FALSE) {if(assign) inp <- inp; getName(inp)} 40 | #' lower2(pi) # "pi" 41 | #' lower2(pi, TRUE) # "3.14159265358979" 42 | #' 43 | #' @param x input object name or character string 44 | #' 45 | getName <- function(x) 46 | { 47 | my.call <- quote(substitute(x)) 48 | var.name <- eval(my.call) 49 | for(i in rev(head(sys.frames(), -1L))) 50 | { 51 | # First frame doesn't matter since we already substituted for first level, 52 | # reverse order of sys.frames (which is in order of evaluation) 53 | my.call[[2]] <- var.name # replace with the modified variable 54 | var.name <- eval(my.call, i) 55 | } 56 | if(!is.character(var.name)) var.name <- deparse(var.name) 57 | return(var.name) 58 | } 59 | -------------------------------------------------------------------------------- /R/googleLink2pdf.R: -------------------------------------------------------------------------------- 1 | #' extract pdf link from google search result 2 | #' 3 | #' restrict pdf link from a google search to actual link with text processing 4 | #' 5 | #' @return Characterstring with only the basic link 6 | #' @note The function is not vectorized! If you have many links, use a loop around this function... 7 | #' @author Berry Boessenkool, \email{berry-b@@gmx.de}, 2012 8 | #' @seealso \code{\link{strsplit}}, \code{\link{gsub}} 9 | #' @keywords character 10 | #' @export 11 | #' @examples 12 | #' 13 | #' Link <- paste0("https://www.google.de/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1", 14 | #' "&cad=rja&sqi=2&ved=0CDIQFjAA&url=http%3A%2F%2Fcran.r-project.org", 15 | #' "%2Fdoc%2Fmanuals%2FR-intro.pdf&ei=Nyl4UfHeOIXCswa6pIC4CA", 16 | #' "&usg=AFQjCNGejDwPlor4togQZmQEQv72cK9z8A&bvm=bv.45580626,d.Yms") 17 | #' googleLink2pdf(Link) 18 | #' 19 | #' Link <- paste0("https://www.google.de/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1", 20 | #' "&cad=rja&uact=8&ved=0ahUKEwjLlfmClavRAhWaN1AKHcGSBjEQFgghMAA", 21 | #' "&url=http%3A%2F%2Fstackoverflow.com%2Fquestions%2Ftagged%2Fr", 22 | #' "&usg=AFQjCNHYj6HjSs6Lvczn9wMWxE3slCdq1Q&bvm=bv.142059868,d.ZWM") 23 | #' googleLink2pdf(Link) 24 | #' Link <- paste0("https://www.google.de/url?sa=t&rct=j&q=&esrc=s&source=web&cd=2", 25 | #' "&cad=rja&uact=8&ved=0ahUKEwjLlfmClavRAhWaN1AKHcGSBjEQFggpMAE&", 26 | #' "url=http%3A%2F%2Fstackoverflow.com%2Fquestions%2Ftagged%2F%3Ftagnames", 27 | #' "%3Dr%26sort%3Dactive&usg=AFQjCNGkPGHq05qwKLLW4vRXdmk2Olhmig&bvm=bv.142059868,d.ZWM") 28 | #' googleLink2pdf(Link) 29 | #' 30 | #' @param googlelink Character string: A search result address 31 | #' 32 | googleLink2pdf <- function( 33 | googlelink 34 | ) 35 | { 36 | pdflink <- strsplit(googlelink, "&url=")[[1]][2] 37 | pdflink <- strsplit(pdflink, "&ei=")[[1]][1] 38 | pdflink <- strsplit(pdflink, "&usg=")[[1]][1] 39 | # printable ascii characters from https://www.ascii-code.com/ 40 | hex <- "20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2F 3A 3B 3C 3D 3E 3F 40" 41 | ascii <- "! \" # $ % & ' ( ) * + , - / : ; < = > ? @" 42 | hex <- paste0("%",strsplit(hex, " ")[[1]]) 43 | ascii <- c(" ",strsplit(ascii, " ")[[1]]) 44 | for(i in seq_along(hex)) pdflink <- gsub(hex[i], ascii[i], pdflink) 45 | pdflink 46 | } 47 | -------------------------------------------------------------------------------- /R/headtail.R: -------------------------------------------------------------------------------- 1 | #' head and tail 2 | #' 3 | #' show head and tail of an object with one command 4 | #' 5 | #' @details Tries to find good methods of combining the two results according to \code{class(x)}. 6 | #' 7 | #' @return \code{\link{head}} result 8 | #' @author Berry Boessenkool, \email{berry-b@@gmx.de}, Mrz 2016 9 | #' @seealso \code{\link{head}} 10 | #' @keywords manip 11 | #' @importFrom utils head tail 12 | #' @export 13 | #' @examples 14 | #' 15 | #' head(letters, n=3) 16 | #' headtail(letters) 17 | #' headtail(letters, n=3) 18 | #' headtail(letters, n=3, na=TRUE) 19 | #' 20 | #' head(letters, n=-10) 21 | #' headtail(letters, n=-10, na=TRUE) # doesn't make sense for headtail 22 | #' 23 | #' head(freeny.x, n=3) # matrix 24 | #' headtail(freeny.x, n=3, na=TRUE) # no names for head-part 25 | #' headtail(women, n=3, na=TRUE) # data.frame works fine 26 | #' 27 | #' head(freeny.y, n=3) 28 | #' headtail(freeny.y, n=3, na=TRUE) 29 | #' 30 | #' head(library, n=3) 31 | #' headtail(library, n=3, na=TRUE) 32 | #' headtail(library, na=TRUE) 33 | #' 34 | #' ftable(Titanic) 35 | #' head(stats::ftable(Titanic), n=4) 36 | #' headtail(stats::ftable(Titanic), n=4, na=TRUE) 37 | #' 38 | #' head(table(sample(1:9, 30, TRUE)), n=3) 39 | #' headtail(table(sample(1:9, 30, TRUE)), n=3, na=TRUE) 40 | #' 41 | #' head(table(state.division, state.region), n=3) 42 | #' headtail(table(state.division, state.region), n=3, na=TRUE) 43 | #' 44 | #' @param x Object 45 | #' @param n Number of elements/rows/lines at begin and end of object to be returned. DEFAULT: 1 46 | #' @param nh,nt Number for \code{\link{head}} and \code{\link{tail}}, respectively. DEFAULT: n 47 | #' @param na Add NA values in between to emphasize visibly that there is 48 | #' something inbetween the values? DEFAULT: FALSE 49 | #' @param \dots Further arguments passed to \code{\link{head}} and \code{\link{tail}} 50 | #' 51 | headtail <- function( 52 | x, 53 | n=1, 54 | nh=n, 55 | nt=n, 56 | na=FALSE, 57 | ... 58 | ) 59 | { 60 | h <- head(x, n=nh, ...) 61 | t <- tail(x, n=nt, ...) 62 | if(inherits(x, "ftable")) noquote(rbind(h,if(na)"-----",t)) else 63 | if(inherits(h, c("data.frame","matrix","table"))) 64 | rbind(h,if(na)NA,t) 65 | else 66 | c(h,if(na)NA,t) 67 | } 68 | -------------------------------------------------------------------------------- /R/if.error.R: -------------------------------------------------------------------------------- 1 | #' expressions/values conditional on whether tested expression returns an error. 2 | #' 3 | #' Does a given expression return an error? 4 | #' Return specific values/expressions for either case. 5 | #' Useful for loops when you want to easily control values based on errors that arise. 6 | #' 7 | #' @return Returns value or expression stated in \code{error_true} or \code{error_false}, 8 | #' depending on whether the tested expression throws an error. 9 | #' @author Nick Bultman, \email{njbultman74@@gmail.com}, September 2020 10 | #' @seealso \code{\link{is.error}} 11 | #' @keywords programming error 12 | #' @export 13 | #' @examples 14 | #' if.error( log(3), "error", "no_error" ) 15 | #' if.error( log(3), "error", log(3) ) 16 | #' if.error( log(3), log(6), "no_error" ) 17 | #' if.error( log("a"), log(6), log(3) ) 18 | #' 19 | #' @param expr Expression to be tested for returning an error. 20 | #' @param error_true Value or expression to be executed if tested expression returns an error. 21 | #' @param error_false Value or expression to be executed if tested expression does not return an error. 22 | #' 23 | if.error <- function( 24 | expr, 25 | error_true, 26 | error_false 27 | ){ 28 | if(is.error(expr)) error_true else error_false 29 | } 30 | -------------------------------------------------------------------------------- /R/is.error.R: -------------------------------------------------------------------------------- 1 | #' Check if an expression returns an error 2 | #' 3 | #' Does a given expression return an error? 4 | #' Useful for tests where you want to make sure your function throws an error. 5 | #' 6 | #' @return TRUE/FALSE 7 | #' @author Berry Boessenkool, \email{berry-b@@gmx.de}, May 2016 8 | #' @seealso \code{\link{stop}}, \code{\link{try}}, \code{\link{inherits}} 9 | #' @keywords programming error 10 | #' @export 11 | #' @examples 12 | #' is.error( log(3) ) 13 | #' is.error( log("a") ) 14 | #' is.error( log(3), tell=TRUE ) 15 | #' is.error( log("a"), tell=TRUE ) 16 | #' stopifnot( is.error( log("a") ) ) # or shorter: 17 | #' is.error( log("a"), force=TRUE) 18 | #' # is.error( log(3), force=TRUE) 19 | #' stopifnot(is.error( is.error(log(3), force=TRUE) )) 20 | #' 21 | #' @param expr Expression to be tested for returning an error 22 | #' @param tell Logical: Should the error message be printed via \code{\link{message}}? DEFAULT: FALSE 23 | #' @param force Logical: Should an error be returned if the expression is not an error? DEFAULT: FALSE 24 | #' 25 | is.error <- function( 26 | expr, 27 | tell=FALSE, 28 | force=FALSE 29 | ) 30 | { 31 | expr_name <- deparse(substitute(expr)) 32 | test <- try(expr, silent=TRUE) 33 | iserror <- inherits(test, "try-error") 34 | if(tell) if(iserror) message("Note in is.error: ", test) 35 | if(force) if(!iserror) stop(expr_name, " is not returning an error.", call.=FALSE) 36 | # output: 37 | iserror 38 | } 39 | -------------------------------------------------------------------------------- /R/legendmt.R: -------------------------------------------------------------------------------- 1 | #' legend with multiline title 2 | #' 3 | #' Draw a legend with title spanning several lines (i.e. with line breaks). 4 | #' Note that this is in development and not all inputs are correctly vectorized yet. 5 | #' 6 | #' @return \code{\link{legend}} output 7 | #' @author Berry Boessenkool, \email{berry-b@@gmx.de}, Apr 2017 8 | #' @seealso \code{\link{legend}} 9 | #' @keywords aplot 10 | #' @importFrom graphics legend par 11 | #' @export 12 | #' @examples 13 | #' plot(1:10) 14 | #' legend("topleft", letters[1:4], col=1:4, pch=1, title="very long title to be split up") 15 | #' legendmt("topleft", letters[1:4], col=1:4, pch=1, title="very long title\nnow splat up") 16 | #' 17 | #' # Alternative: 18 | #' plot(1:10) 19 | #' legend("topleft", "very long title to be split up") 20 | #' legend("topleft", letters[1:4], col=1:4, pch=1, inset=c(0,0.09) ) 21 | #' 22 | #' @param x,y,legend Arguments as in \code{\link{legend}} 23 | #' @param title Character with linebreaks or vector of charstrings. 24 | #' @param x.intersp,fill,col,border,lty,lwd,pch Arguments as in \code{\link{legend}} 25 | #' @param \dots Further arguments passed to \code{\link{legend}}. 26 | #' If vectorized, please remember to prepend NAs or whatever. 27 | #' 28 | legendmt <- function( 29 | x, 30 | y=NULL, 31 | legend, 32 | title, 33 | x.intersp=1, 34 | fill=NA, 35 | col=par("col"), 36 | border=NA, 37 | lty=NA, 38 | lwd=NA, 39 | pch=NA, 40 | ... 41 | ) 42 | { 43 | ## the 2nd arg may really be `legend' 44 | if(missing(legend) && !missing(y) && (is.character(y) || is.expression(y))) 45 | { 46 | legend <- y 47 | y <- NULL 48 | } 49 | # title must be a vector of strings: 50 | title <- unlist(strsplit(title,"\n")) 51 | # prepend values: 52 | lt <- length(title) 53 | ll <- length(legend) 54 | nas <- rep_len(NA,lt) 55 | x.intersp <- c(rep_len(0,lt), rep_len(x.intersp,ll) ) 56 | fill <- c(nas, rep_len(fill, ll) ) 57 | col <- c(nas, rep_len(col, ll) ) 58 | border <- c(nas, rep_len(border,ll) ) 59 | lty <- c(nas, rep_len(lty, ll) ) 60 | lwd <- c(nas, rep_len(lwd, ll) ) 61 | pch <- c(nas, rep_len(pch, ll) ) 62 | # legend 63 | legend <- c(title,legend) 64 | # actual drawing: 65 | graphics::legend(x,y,legend, x.intersp=x.intersp, fill=fill, col=col, 66 | border=border, lty=lty, lwd=lwd, pch=pch, ...) 67 | } 68 | -------------------------------------------------------------------------------- /R/library2.R: -------------------------------------------------------------------------------- 1 | #' install.package and library 2 | #' 3 | #' install and load a package. If a package is not available, it is installed before being loaded 4 | #' 5 | #' @aliases library2 require2 6 | #' @return \code{\link{message}s} help instruction. 7 | #' @note Passing a vector with packages will work, but give some warnings. 8 | #' @author Berry Boessenkool, \email{berry-b@@gmx.de}, 2014+2020 9 | #' @seealso \code{\link{install.packages}}, \code{\link{library}} 10 | #' @keywords package 11 | #' @importFrom utils install.packages 12 | #' @export 13 | #' @examples 14 | #' 15 | #' \dontrun{ 16 | #' ## Excluded fom CRAN checks. Package installation on server is unnecessary. 17 | #' require2(ada) 18 | #' library2("statmod") 19 | #' } 20 | #' 21 | #' @param name Name of the package(s). Can be quoted, must not. 22 | #' @param quietly passed to \code{\link{library}}. DEFAULT: FALSE 23 | #' @param libargs List of arguments passed to \code{\link{library}} like \code{lib.loc}, \code{verbose} etc. DEFAULT: NULL 24 | #' @param \dots Arguments passed to \code{\link{install.packages}} like \code{lib}, \code{repos} etc. 25 | #' 26 | library2 <- function( 27 | name, 28 | quietly=FALSE, 29 | libargs=NULL, 30 | ...) 31 | { 32 | name <- as.character(substitute(name)) 33 | for(n in name) 34 | { 35 | if(!requireNamespace(n, quietly=TRUE)) install.packages(n, ...) 36 | libdef <- list(package=n, character.only=TRUE, quietly=quietly) 37 | do.call(library, owa(libdef, libargs, "package", "character.only")) 38 | } 39 | } 40 | 41 | #' @export 42 | require2 <- library2 43 | -------------------------------------------------------------------------------- /R/locArrow.R: -------------------------------------------------------------------------------- 1 | #' arrow at locator point in graph 2 | #' 3 | #' Draw arrow at positions in a graph located by clicking and return the code to recreate it 4 | #' 5 | #' @details Not tested across platforms yet... 6 | #' 7 | #' @return Character string with code 8 | #' @author Berry Boessenkool, \email{berry-b@@gmx.de}, Jun 2016 9 | #' @seealso \code{\link{locLine}}, \code{\link{locator}}, \code{\link{abline}} 10 | #' @keywords aplot iplot 11 | #' @importFrom graphics locator arrows 12 | #' @export 13 | #' @examples 14 | #' 15 | #' plot(cumsum(rnorm(60)), type="l") 16 | #' ## locArrow() # only do this manually in interactive() mode 17 | #' ## locArrow(col="blue", lwd=3) 18 | #' 19 | #' @param digits Number of digits coordinates are rounded to with \code{\link{signif}} 20 | #' @param length Length of the edges of the arrow head (in inches). DEFAULT: 0.1 21 | #' @param code Direction of arrow head. DEFAULT: 2 (from first to last point clicked) 22 | #' @param \dots Further arguments passed to \code{\link{arrows}} like lwd, col etc 23 | #' 24 | locArrow <- function( 25 | digits=2, 26 | length=0.1, 27 | code=2, 28 | ... 29 | ) 30 | { 31 | # get coordinates: 32 | coord <- locator(n=2) 33 | coord$x <- signif(coord$x, digits) 34 | coord$y <- signif(coord$y, digits) 35 | # concatenate basic arguments into character string: 36 | command <- paste0("arrows(x0=",coord$x[1],", x1=",coord$x[2], 37 | ", y0=",coord$y[1],", y1=",coord$y[2], 38 | ", length=",length,", code=",code ) 39 | # concatenate further arguments, obeying quotation marks: 40 | arg <- list(...) 41 | sQuote2 <- function(x) if(is.character(x)) paste0("'", x, "'") else x 42 | arg2 <- lapply(arg, sQuote2) 43 | arg3 <- toString( paste(names(arg2), arg2, sep="=") ) 44 | if(arg3 != "") arg3 <- paste(",", arg3) 45 | # Put both together: 46 | command <- paste0(command, arg3, ")") 47 | # evaluate and return the command string: 48 | eval(parse(text=command)) 49 | command 50 | } 51 | -------------------------------------------------------------------------------- /R/locLine.R: -------------------------------------------------------------------------------- 1 | #' abline at locator point in graph 2 | #' 3 | #' Draw vertical and/or horizontal lines at positions in a graph located by clicking 4 | #' 5 | #' @details Not tested across platforms yet... 6 | #' @return \code{\link{locator}} result 7 | #' @author Berry Boessenkool, \email{berry-b@@gmx.de}, Mar 2016 8 | #' @seealso \code{\link{locArrow}}, \code{\link{locator}}, \code{\link{abline}} 9 | #' @keywords aplot iplot 10 | #' @importFrom graphics abline locator 11 | #' @export 12 | #' @examples 13 | #' 14 | #' plot(cumsum(rnorm(60)), type="l") 15 | #' ## locLine() # only do this manually in interactive() mode 16 | 17 | #' @param h Draw horizontal line at clicked location? DEFAULT: TRUE 18 | #' @param v Draw vertical line at clicked location? DEFAULT: TRUE 19 | #' @param n Number of points to be clicked. DEFAULT: 1 20 | #' @param \dots Further arguments passed to \code{\link{abline}} like lty, lwd, col, etc 21 | 22 | locLine <- function( 23 | h=TRUE, 24 | v=TRUE, 25 | n=1, 26 | ... 27 | ) 28 | { 29 | coord <- locator(n=n) 30 | if(h) abline(h=coord$y, ...) 31 | if(v) abline(v=coord$x, ...) 32 | coord 33 | } 34 | -------------------------------------------------------------------------------- /R/locatorRS.R: -------------------------------------------------------------------------------- 1 | #' @title locator with immediate points in Rstudio 2 | #' @description Have \code{\link{locator}} add points on the graph directly after clicking, even in Rstudio Graphics devices 3 | #' @return List with x and y 4 | #' @author Berry Boessenkool, \email{berry-b@@gmx.de}, Dec 2020 5 | #' @seealso \url{https://stackoverflow.com/q/65147219/1587132} 6 | #' @keywords aplot 7 | #' @export 8 | #' @examples 9 | #' if(interactive()){ 10 | #' plot(1:10, type="n") 11 | #' locs <- locator(n=3, type="o") # click on locations in graph. 12 | #' # If you do not set n at beginning, press ESC to finish 13 | #' locs 14 | #' # In Rstudio, points only appear after finishing. 15 | #' locatorRS(7, col="blue", type="o") # plots after each click 16 | #' } 17 | #' 18 | #' @param n Maximum number of points to plot. 19 | #' @param type As in \code{\link{locator}}, but passed to \code{\link{points}}. 20 | #' DEFAULT: "p" 21 | #' @param \dots Further arguments passed to \code{\link{points}} 22 | #' 23 | locatorRS <- function( 24 | n=512, 25 | type="p", 26 | ... 27 | ) 28 | { 29 | on.exit(list(x=x,y=y)) # output even when function is canceled with ESC in console 30 | x <- y <- NULL 31 | for(i in seq_len(n)) 32 | { 33 | d <- locator(1) 34 | if(is.null(d)) break # If user pressed ESC in Rstudio Graphics window 35 | x <- c(x, d$x) 36 | y <- c(y, d$y) 37 | points(x,y, type=type, ...) 38 | } 39 | list(x=x, y=y) 40 | } 41 | -------------------------------------------------------------------------------- /R/lsMem.R: -------------------------------------------------------------------------------- 1 | #' Show memory size of objects in MB 2 | #' 3 | #' Show memory size of the biggest objects in MB. Helps you find the biggest memory killers. 4 | #' 5 | #' @return Named vector with object sizes in MB (MegaBytes) 6 | #' @author Berry Boessenkool, \email{berry-b@@gmx.de}, Feb 2014 7 | #' @seealso \code{\link{object.size}}, \code{\link{ls}} 8 | #' @references \url{https://stackoverflow.com/questions/1358003/tricks-to-manage-the-available-memory-in-an-r-session} 9 | #' @keywords programming file 10 | #' @importFrom utils object.size 11 | #' @export 12 | #' @examples 13 | #' 14 | #' \dontrun{ 15 | #' ## excluded from CRAN check - I forgot why, but there's probably a good reason 16 | #' lsMem() 17 | #' } 18 | #' 19 | #' @param n Number of Objects to be shown separately. The rest is combined into "sum rest". DEFAULT: 6 20 | #' @param pos Environment where \code{\link{ls}} looks for objects. 21 | #' @param \dots Further arguments passed to \code{\link{ls}} 22 | #' 23 | lsMem <- function( 24 | n=6, 25 | pos=1, 26 | ...) 27 | { 28 | LS <- ls(pos=pos, ...) 29 | if(n > length(LS)) n <- length(LS) 30 | size <- sapply(LS, function(x) object.size(get(x))) 31 | output <- sort(size/1e6, decreasing=TRUE) 32 | if(n < length(LS)) c(output[1:n], "sum rest:"=sum(output[-(1:n)])) 33 | else 34 | output 35 | } 36 | -------------------------------------------------------------------------------- /R/movAvLines.R: -------------------------------------------------------------------------------- 1 | #' Moving average with different window widths 2 | #' 3 | #' Add moving average lines with different window widths to a plot 4 | #' 5 | #' @author Berry Boessenkool, \email{berry-b@@gmx.de}, May 2015 6 | #' @seealso \code{\link{movAv}}, \code{\link{addAlpha}} 7 | #' @keywords ts manip smooth 8 | #' @importFrom graphics lines plot 9 | #' @export 10 | #' @examples 11 | #' 12 | #' set.seed(42) 13 | #' movAvLines(y=cumsum(rnorm(50)), add=FALSE, lwd=3) 14 | #' 15 | #' @param x x values of data. DEFAULT: 1:length(y) 16 | #' @param y y values that are smoothed with several window widths 17 | #' @param widths widths of \code{\link{movAv}} windows. DEFAULT: 2:7*2-1 18 | #' @param weights weights within each window 19 | #' @param col color passed to \code{\link{addAlpha}}. DEFAULT: "blue" 20 | #' @param alpha transparency passed to \code{\link{addAlpha}}. DEFAULT: 0.3 21 | #' @param add Logical: Add to existing plot?Set to FALSE to first create 22 | #' the scatterplot. DEFAULT: TRUE 23 | #' @param las LabelAxisStyle (only relevant if add=FALSE). DEFAULT: 1 24 | #' @param \dots further arguments passed to \code{\link{lines}} 25 | #' 26 | movAvLines <- function( 27 | x=1:length(y), 28 | y, 29 | widths=c(3,5,7,9,11,13), 30 | weights, 31 | col="blue", 32 | alpha=0.3, 33 | add=TRUE, 34 | las=1, 35 | ... 36 | ) 37 | { 38 | if(!add) plot(x,y, las=las) 39 | for(i in 1:length(widths)) 40 | lines(x, movAv(y, width=widths[i], weights=weights), col=addAlpha(col, alpha), ...) 41 | } 42 | 43 | -------------------------------------------------------------------------------- /R/na9.R: -------------------------------------------------------------------------------- 1 | #' Prepend spaces before na.strings 2 | #' 3 | #' Returns a number of useful character strings with varying amount of spaces prepended. 4 | #' It can be used as \code{na.strings=na9()} in \code{\link{read.table}}. 5 | #' 6 | #' @return Character strings 7 | #' @author Berry Boessenkool, \email{berry-b@@gmx.de}, Jan 2016 8 | #' @seealso \code{\link{paste}} 9 | #' @keywords IO file 10 | #' @export 11 | #' @examples 12 | #' 13 | #' na9() 14 | #' na9(nspace=0, sep=".") 15 | #' na9(nspace=0, sep=".", more=c(NA,"-")) 16 | #' 17 | #' @param nspace number of spaces prepended. DEFAULT: 5 18 | #' @param base Numeric: basic na.string numbers 19 | #' @param sep Separator string (comma or decimal point or both). DEFAULT: c(",",".") 20 | #' @param digits Number(s) of zeros to be appended. DEFAULT: 0:4 21 | #' @param more More structures added to base, like "NA", "--". digits and sep is not added to this! DEFAULT: NULL 22 | #' @param \dots Arguments passed to nothing currently 23 | #' 24 | na9 <- function( 25 | nspace=5, 26 | base=c(-9999,-999, -9.99, -9.999), 27 | sep=c(",","."), 28 | digits=0:4, 29 | more=NULL, 30 | ...) 31 | { 32 | # zeros: 33 | base <- c(sapply(digits, function(d) sapply(base, format, nsmall=d) )) 34 | # separator signs: 35 | base <- c(sapply(sep, function(s) gsub(".", s, base, fixed=TRUE) )) 36 | # spaces: 37 | spaces <- sapply(0:nspace, function(i) paste(rep(" ",i), collapse="")) 38 | base <- paste0(rep(spaces, each=length(base)), base) 39 | # add more: 40 | base <- c(base, more) 41 | # output: 42 | unique(base) 43 | } 44 | -------------------------------------------------------------------------------- /R/openFile.R: -------------------------------------------------------------------------------- 1 | #' @title open file in default application 2 | #' @description open a file using \code{\link{system2}} with command based on operating system. 3 | #' Tries to open the file with the program associated with its file extension.\cr 4 | #' See \code{\link{openPDF}} to open files with sumatraPDF. 5 | #' @return Result of try(system2, ...), invisibly 6 | #' @author Berry Boessenkool, \email{berry-b@@gmx.de}, Aug 2017 7 | #' @seealso \code{\link{openPDF}}, \code{\link{system2}}, \code{\link{checkFile}} 8 | #' @references \url{https://askubuntu.com/questions/15354}, 9 | #' \url{https://apple.stackexchange.com/questions/212583} 10 | #' @keywords file 11 | # @importFrom package fun1 fun2 12 | #' @export 13 | #' @examples 14 | #' \dontrun{ # excluded from CRAN checks, file opening not wanted 15 | #' openFile("README.md") 16 | #' openFile("Tests.R") 17 | #' openFile(c("README.md","Tests.R")) 18 | #' is.error(openFile("dummydummydoesntexist.R"), TRUE, TRUE) 19 | #' openFile(tempdir()) 20 | #' } 21 | #' #' # To open folders (not files) with system2: 22 | #' # "nautilus" on linux ubuntu 23 | #' # "open" or "dolphin" on mac 24 | #' # "explorer" or "start" on windows 25 | #' # But open / xdg-open seems to work as well 26 | #' 27 | #' @param file Filename to be opened, as character string. 28 | #' @param \dots Further arguments passed to \code{\link{system2}} 29 | #' 30 | openFile <- function( 31 | file, 32 | ... 33 | ) 34 | { 35 | file <- normalizePath(file, winslash="/", mustWork=FALSE) 36 | checkFile(file) 37 | file <- shQuote(file) # to handle space in "C:/Program Files/R/..." 38 | sysname <- Sys.info()["sysname"] 39 | out <- try(switch(sysname, 40 | "Linux" = system2("xdg-open", file, ...), 41 | "FreeBSD" = system2("handlr", paste("open",file), ...), 42 | system2("open", file, ...) # Windows 43 | ), 44 | silent=TRUE) 45 | # out: 127 if failed, 124 for timeout, 0 for success 46 | 47 | return(invisible(out)) 48 | } 49 | -------------------------------------------------------------------------------- /R/packagePath.R: -------------------------------------------------------------------------------- 1 | #' @title Base path of package 2 | #' @description Base path of package (with DESCRIPTION file), per default at current getwd. 3 | #' Derived from devtools::package_file 4 | #' @return Path character string 5 | #' @author Berry Boessenkool, \email{berry-b@@gmx.de}, Sep 2017 6 | #' @seealso \code{\link{getwd}} 7 | #' @keywords file 8 | #' @export 9 | #' @examples 10 | #' # packagePath() # may fail on cran checks 11 | #' 12 | #' @param path Path to (or below) package directory. DEFAULT: "." 13 | #' @param file Optional file name to be added to path. DEFAULT: NA 14 | #' @param warnonly Logical: if no part of the path is a package, give a warning 15 | #' and return the original input instead of stopping with an error. 16 | #' DEFAULT: FALSE 17 | #' 18 | packagePath <- function( 19 | path=".", 20 | file=NULL, 21 | warnonly=FALSE 22 | ) 23 | { 24 | path <- path0 <- normalizePath(path, winslash="/", mustWork=FALSE) 25 | checkFile(path, pwd=FALSE) 26 | # Go up the path until DESCRIPTION exists 27 | while(!file.exists(file.path(path, "DESCRIPTION"))) 28 | { 29 | path <- dirname(path) 30 | # Error if path0 was not below or at a package: 31 | if(path==dirname(path)) 32 | { 33 | message <- paste0(traceCall(skip=1, prefix="in ", suffix=":\n"), 34 | "Package root directory (containing DESCRIPTION file) ", 35 | "could not be found for ", path0) 36 | if(!warnonly) stop(message, call.=FALSE) 37 | else {warning(message, call.=FALSE); return(path0)} 38 | } 39 | } 40 | if(!is.null(file)) path <- paste0(path, "/", sub("^/","",file)) 41 | path 42 | } 43 | -------------------------------------------------------------------------------- /R/parallelCode.R: -------------------------------------------------------------------------------- 1 | #' @title code chunk for parallelization 2 | #' @description message a code chunk template for parallelization with progress bar on windows. 3 | #' On Linux, just use \code{pblapply(X, cl=8, FUN=fun)} 4 | #' @author Berry Boessenkool, \email{berry-b@@gmx.de}, Aug 2017 5 | #' @seealso \code{\link{par_sapply}} 6 | #' @export 7 | #' @examples 8 | #' parallelCode() 9 | #' 10 | parallelCode <- function() 11 | { 12 | message( 13 | '# Pseudo function and objects: 14 | obj1 <- obj2 <- obj3 <- "someStuff" 15 | fun <- function(x) nchar(obj1) + mean(rnorm(1e5)) 16 | input <- 1:100 17 | 18 | library(pbapply); library(parallel) # for parallel lapply execution 19 | cl <- makeCluster( detectCores()-1 ) 20 | clusterExport(cl, c("obj1", "obj2", "obj3")) 21 | output <- pbsapply(X=input, cl=cl, FUN=fun, simplify=FALSE) 22 | stopCluster(cl); rm(cl); gc() 23 | ' 24 | ) 25 | } 26 | -------------------------------------------------------------------------------- /R/popleaf.R: -------------------------------------------------------------------------------- 1 | #' create leaflet popup box info 2 | #' 3 | #' combine data.frame columns into a leaflet popup-box compatible format 4 | #' 5 | #' @return Vector with character strings 6 | #' @author Berry Boessenkool, \email{berry-b@@gmx.de}, Apr 2017 7 | #' @seealso \code{\link{paste}} 8 | #' @keywords aplot 9 | #' @export 10 | #' @examples 11 | #' dat <- data.frame(a=14:16, b=letters[14:16], c=LETTERS[14:16], 12 | #' lat=c(52.58,53.45,52.4), lon=c(6.34,7.23,13.05)) 13 | #' popleaf(dat) 14 | #' dat$display <- popleaf(dat, 1:4) 15 | #' 16 | #' \dontrun{ # Excluded from CRAN checks 17 | #' library(leaflet) 18 | #' leaflet(dat) %>% addTiles() %>% addCircleMarkers(~lon, ~lat, popup=~display) 19 | #' } 20 | #' 21 | #' dat[1,1] <- "Very long string I'd rather have truncated" 22 | #' popleaf(dat, 1:3) 23 | #' popleaf(dat, 1:3, truncate=16) 24 | #' popleaf(dat, 1:3, truncate=16, tstring="--") 25 | #' 26 | #' @param df Data.frame 27 | #' @param sel Columns to be selected (Names or index or TRUE/FALSE vector). 28 | #' DEFAULT: colnames(df) 29 | #' @param truncate Numeric: number of characters beyond which to truncate columns. 30 | #' DEFAULT: NULL (no truncation) 31 | #' @param tstring Charstring to add at the end if truncated. DEFAULT: "[...]" 32 | #' @param exclude_geometry Remove column with the name "geometry" 33 | #' (as in sf objects) from the display? DEFAULT: TRUE 34 | #' @param na.rm Exclude NA entries from the display? DEFAULT: FALSE 35 | #' 36 | popleaf <- function( 37 | df, 38 | sel=colnames(df), 39 | truncate=NULL, 40 | tstring="[...]", 41 | exclude_geometry=TRUE, 42 | na.rm=FALSE 43 | ) 44 | { 45 | df <- as.data.frame(df) # otherwise the next line doesn't work for sf 46 | sel <- colnames(df[,sel, drop=FALSE]) 47 | if(exclude_geometry) sel <- sel[sel!="geometry"] 48 | truncString <- function(x, n) ifelse(nchar(x)>n, paste0(substring(x, 1, n), tstring), x) 49 | apply(df, MARGIN=1, function(x) 50 | { 51 | nna <- if(na.rm) !is.na(x[sel]) else TRUE 52 | sel <- sel[nna] 53 | value <- x[sel] 54 | if(!is.null(truncate)) value <- truncString(value, truncate) 55 | paste(sel, ": ", value, collapse="
") 56 | }) 57 | } 58 | -------------------------------------------------------------------------------- /R/pretty2.R: -------------------------------------------------------------------------------- 1 | #' Truncated pretty breakpoints 2 | #' 3 | #' \code{\link{pretty}} with no values outside of x range 4 | #' 5 | #' calculates \code{pretty(x)}, then removes the values that do not lie within 6 | #' \code{\link{range}(x)}.\cr If force=TRUE, range(x) is reduced step by step 7 | #' in a while loop until the condition is met. This is useful if you want 8 | #' exactly 2 labels on an \code{\link{axis}}. In order not to get stuck, the 9 | #' outer values are taken if there are more than n values within range(x). 10 | #' 11 | #' @author Berry Boessenkool, \email{berry-b@@gmx.de}, Aug 2014 12 | #' @seealso \code{\link{pretty}} , \code{\link{logVals}} 13 | #' @keywords dplot 14 | #' @importFrom grDevices extendrange 15 | #' @export 16 | #' @examples 17 | #' 18 | #' k <- c(135, 155, 120, 105, 140, 130, 190, 110) 19 | #' range(k) 20 | #' pretty(k) 21 | #' pretty2(k) 22 | #' 23 | #' pretty(c(0.2, 0.9), n=2) 24 | #' pretty2(c(0.2, 0.9), n=2) 25 | #' pretty2(c(0.2, 0.9), n=2, force=TRUE) 26 | #' 27 | #' @param x object with numeric values 28 | #' @param n desired number of values in \code{\link{pretty}}. DEFAULT: 5 29 | #' @param force Must output length equal n exactly? DEFAULT: FALSE 30 | #' @param \dots all other arguments in \code{\link{pretty}}. 31 | #' 32 | pretty2 <- function( 33 | x, 34 | n=5, 35 | force=FALSE, 36 | ...) 37 | { 38 | p <- pretty(x, n=n, ...) 39 | r <- range(x, finite=TRUE) 40 | p <- p[p>=r[1] & p<=r[2]] 41 | if(force) # Added March 2015 42 | while(length(p) != n) 43 | { 44 | x <- extendrange(x, f=-0.01) 45 | p <- pretty(x, n=n, ...) 46 | p <- p[p>=r[1] & p<=r[2]] 47 | if(length(p) > n) p <- range(p) 48 | } 49 | p 50 | } 51 | 52 | -------------------------------------------------------------------------------- /R/rainbow2.R: -------------------------------------------------------------------------------- 1 | #' Rainbow from blue to red 2 | #' 3 | #' Reversed \code{\link{rainbow}} with different defaults, resulting in a color vector from blue (good) to red (bad) 4 | #' 5 | #' @return A character vector of color names. 6 | #' @author Berry Boessenkool, \email{berry-b@@gmx.de}, Sept 2014 7 | #' @seealso \code{\link{seqPal}} for a better palette, \code{\link{rainbow}} 8 | #' @keywords color dplot 9 | #' @importFrom grDevices rainbow 10 | #' @export 11 | #' @examples 12 | #' 13 | #' plot(1:10, pch=16, cex=2, col=rainbow2(10)) 14 | #' 15 | #' @param n number of colors. DEFAULT: 10 16 | #' @param s,v saturation and value as in \code{\link{rainbow}}. DEFAULT: 1 17 | #' @param start start color. DEFAULT: 0 18 | #' @param end end color. DEFAULT: 0.7 19 | #' @param alpha transparency. DEFAULT: 1) 20 | #' 21 | rainbow2 <- function( 22 | n=10, 23 | s=1, v=1, 24 | start=0, 25 | end=0.7, 26 | alpha=1) 27 | { 28 | #warning("rainbow2 will be removed late 2019. use seqPal instead.") 29 | rev(rainbow(n=n, s=s, v=v, start=start, end=end, alpha=alpha)) 30 | } 31 | -------------------------------------------------------------------------------- /R/removeSpace.R: -------------------------------------------------------------------------------- 1 | #' Remove white spaces from strings 2 | #' 3 | #' Remove leading and/or trailing white space from character strings 4 | #' 5 | #' @return Character string (vector) 6 | #' @note If all arguments are FALSE, the string is returned unchanged.\cr Not 7 | #' extensively tested yet, please mail me any problems... 8 | #' @author Berry Boessenkool, \email{berry-b@@gmx.de}, Dec 2014 9 | #' @seealso \code{\link{sub}}, \code{\link{trimws}} since R 3.2.0 (April 2015) 10 | #' @keywords character 11 | #' @export 12 | #' @examples 13 | #' 14 | #' s <- c("space at end ", " white at begin", " both ", " special ^ ") 15 | #' removeSpace(s) 16 | #' trimws(s) 17 | #' 18 | #' # To add space, use: 19 | #' x <- c("ab","abcde") 20 | #' format(x) 21 | #' format(x, justify="centre") 22 | #' format(x, width=9) 23 | #' 24 | #' @param x Character string, can be a vector 25 | #' @param begin Logical. Remove leading spaces at the beginning of the character string? DEFAULT: TRUE 26 | #' @param end Logical. Remove trailing spaces at the end? DEFAULT: TRUE 27 | #' @param all Logical. Remove all spaces anywhere in the string? DEFAULT: FALSE 28 | #' @param \dots Further arguments passed to \code{\link{sub}} or \code{\link{gsub}}, like \code{ignore.case, perl, fixed, useBytes}. 29 | #' 30 | removeSpace <- function( 31 | x, 32 | begin=TRUE, 33 | end=TRUE, 34 | all=FALSE, 35 | ... 36 | ) 37 | { 38 | warning("since R 3.2.0 (April 2015), there is trimws(). removeSpace() will be removed from berryFunctions one day.") 39 | if(all) gsub(pattern=" ", replacement="", x=x, ...) else 40 | if(begin&end) sub("^[[:space:]]*(.*?)[[:space:]]*$", "\\1", x, perl=TRUE, ...) else 41 | if(end) sub(" +$", '', x) else 42 | if(begin) sub("^\\s+", "", x) else 43 | x 44 | } 45 | -------------------------------------------------------------------------------- /R/rescale.R: -------------------------------------------------------------------------------- 1 | #' shift and scale a vector 2 | #' 3 | #' rescale a numeric vector: map values linearly onto a given range 4 | #' 5 | #' @return numeric vector, rescaled onto output range 6 | #' @author Berry Boessenkool, \email{berry-b@@gmx.de}, Jan 2016 7 | #' @seealso \code{scales::rescale} 8 | #' @references \url{https://stackoverflow.com/a/18303620} 9 | #' @keywords manip 10 | #' @export 11 | #' @examples 12 | #' 13 | #' rescale(10:15, 135, 200) 14 | #' rescale(10:15, 200, 135) 15 | #' rescale(10:15, to=c(1,5)) 16 | #' 17 | #' values <- rbeta(1e3, shape1=4, shape2=35) 18 | #' hist(rescale(values, 135, 200), breaks=25, col=3) 19 | #' 20 | #' @param x Numerical vector of values to be mapped to a given range 21 | #' @param from output minimum. DEFAULT: 0 22 | #' @param to output maximum. DEFAULT: 1 23 | #' 24 | rescale <- function( 25 | x, 26 | from=0, 27 | to=1 28 | ) 29 | { 30 | if(length(from)!=1) warning("from has length ", length(from)) 31 | if(length(to)!=1) warning( "to has length ", length(to)) 32 | (x-min(x, na.rm=TRUE)) / (max(x, na.rm=TRUE)-min(x, na.rm=TRUE)) * (to - from) + from 33 | } 34 | 35 | -------------------------------------------------------------------------------- /R/round0.R: -------------------------------------------------------------------------------- 1 | #' Round numbers with leading and trailing zeros 2 | #' 3 | #' Round numbers and add leading + trailing zeros 4 | #' 5 | #' @return Character string vector 6 | #' @author Berry Boessenkool, \email{berry-b@@gmx.de}, Jun 2017 7 | #' @seealso \code{\link{formatC}}, \code{\link{sprintf}} 8 | #' @export 9 | #' @examples 10 | #' round0( pi*10^(-3:5), 2) 11 | #' stopifnot(round0(17.3, 2) == "17.30") 12 | #' round0(7.3) 13 | #' round0(c(7.3,777.1234), 2) 14 | #' round0(c(0.2,7.3,12.8), 2, pre=1) 15 | #' round0(c(0.2,7.3,12.8), 1, pre=3, flag="") # spaces instead of zeros 16 | #' 17 | #' @param x Value(s) 18 | #' @param digits Number of digits (after decimal separator) to keep. DEFAULT: 0 19 | #' @param pre Minimum number of characters before the decimal separator. DEFAULT: 2 20 | #' @param width Total width (number of characters including dot). 21 | #' DEFAULT: digits+pre (+1 if needed) 22 | #' @param flag Flag. Could be "" for spaces. DEFAULT: "0" 23 | #' @param \dots Further arguments passed to \code{\link{formatC}}, 24 | #' except for "format". 25 | #' 26 | round0 <- function( 27 | x, 28 | digits=0, 29 | pre=2, 30 | width=digits+pre+ifelse(digits==0,0,1), 31 | flag=0, 32 | ... 33 | ) 34 | { 35 | formatC(round(x,digits), format='f', digits=digits, width=width, flag=flag, ...) 36 | } 37 | -------------------------------------------------------------------------------- /R/runAxis.R: -------------------------------------------------------------------------------- 1 | #' Label axis with typical running times 2 | #' 3 | #' Label a numerical axis (in minutes) with time units that are typical for running times (10 sec intervals) 4 | #' 5 | #' @return List with the positions and labels 6 | #' @author Berry Boessenkool, \email{berry-b@@gmx.de}, Jun 2016 7 | #' @seealso \code{\link{logAxis}}, \code{\link{monthAxis}} 8 | #' @keywords aplot 9 | #' @importFrom graphics axis box 10 | #' @export 11 | #' @examples 12 | #' plot(1:200, xaxt="n") 13 | #' runAxis(t=200, int1=20, int2=10) 14 | #' 15 | #' @param t Maximum time in minutes 16 | #' @param int1 Primary interval (for labels) 17 | #' @param int2 Secondary interval (for lines) 18 | #' @param side Side of the plot to draw \code{\link{axis}} (1,2,3,4 = bottom, left, top, right) 19 | #' @param linarg List of arguments passed to \code{\link{abline}} 20 | #' @param \dots Further arguments passed to \code{\link{axis}} 21 | #' 22 | runAxis <- function( 23 | t=3*60, 24 | int1=10, 25 | int2=5, 26 | side=1, 27 | linarg=NULL, 28 | ... 29 | ) 30 | { 31 | x1 <- seq(0, max(t,na.rm=TRUE), by=int1) 32 | l1 <- paste0(x1%/%60, ":", formatC(x1%%60, width=2, flag="0")) 33 | x2 <- seq(0, max(t,na.rm=TRUE), by=int2) 34 | l2 <- paste0(x2%/%60, ":", formatC(x2%%60, width=2, flag="0")) 35 | axis(side=side, x1, l1, ...) 36 | if(side%in% c(1,3)) do.call(abline, owa(list(v=x2, col=8), linarg)) else 37 | do.call(abline, owa(list(h=x2, col=8), linarg)) 38 | box() 39 | return(invisible(list(x1=x1, l1=l1, x2=x2, l2=l2))) 40 | } 41 | -------------------------------------------------------------------------------- /R/runRversions.R: -------------------------------------------------------------------------------- 1 | #' @title Run code in several R versions 2 | #' @description Run code / script in several local R versions 3 | #' @return Results from each run 4 | #' @author Berry Boessenkool, \email{berry-b@@gmx.de}, May 2022 5 | #' @seealso \code{\link{help}} 6 | #' @export 7 | #' @examples 8 | #' tfile <- tempfile(fileext=".R") 9 | #' cat( 10 | #' 'trace <- function() paste(sapply(sys.calls(),function(x) 11 | #' strsplit(deparse(x),"(", fixed=TRUE)[[1]][1]), collapse=" -> ") 12 | #' lower <- function(a) {message(trace(), " - msg with ", a+10); a} 13 | #' upper <- function(b) lower(b+5) 14 | #' upper(3)', file=tfile) 15 | #' 16 | #' # Don't actually run with example testing 17 | #' # out <- source(tfile) ; out$value # message + output 8 18 | #' # runRversions(tfile) 19 | #' # runRversions(expr=5+7) 20 | #' 21 | #' @param scpt File path to script. DEFAULT: NULL 22 | #' @param expr Expression to be run. DEFAULT: NULL 23 | #' @param path Location of R versions. DEFAULT: "C:/Program Files/R/" 24 | #' @param vrns R Versions at path. DEFAULT: dir(path,pattern="R-") 25 | #' @param exec Local path to Rscript. DEFAULT: "/bin/Rscript.exe" 26 | #' 27 | runRversions <- function( 28 | scpt=NULL, 29 | expr=NULL, 30 | path="C:/Program Files/R/", 31 | vrns=dir(path, pattern="R-"), 32 | exec="/bin/Rscript.exe" 33 | ) 34 | { 35 | fullexes <- paste0(path,vrns,exec) 36 | expr_char <- deparse(substitute(expr)) 37 | if(!is.null(scpt)){ 38 | scpt <- normalizePathCP(scpt) 39 | checkFile(scpt) 40 | out <- pbapply::pblapply(fullexes, system2, scpt, stdout=TRUE) 41 | } 42 | if(!is.null(expr)){ 43 | # system2(fullexes[1], paste("-e",shQuote(expr_char))) 44 | out <- pbapply::pblapply(fullexes, system2, paste("-e",shQuote(expr_char)), stdout=TRUE) 45 | } 46 | names(out) <- vrns 47 | out 48 | } 49 | -------------------------------------------------------------------------------- /R/runTime.R: -------------------------------------------------------------------------------- 1 | #' @title runnning time conversion 2 | #' @description display runnning times in useful units 3 | #' @return list with time elements 4 | #' @author Berry Boessenkool, \email{berry-b@@gmx.de}, Jun 2020 5 | #' @seealso \code{\link{runAxis}} 6 | # @importFrom package fun1 fun2 7 | #' @export 8 | #' @examples 9 | #' runTime(d=3.6, t="15:40") 10 | #' runTime(d=3.6, t="15:10") 11 | #' runTime(d=3.6, t="14:50") 12 | #' 13 | #' @param d Numerical value: distance [km] 14 | #' @param t Charstring: time ["MM:SS"] 15 | #' 16 | runTime <- function( 17 | d, 18 | t 19 | ) 20 | { 21 | tsec <- strsplit(t, ":")[[1]] 22 | tsec <- as.numeric(tsec) 23 | tsec <- tsec[1]*60 + tsec[2] 24 | pace <- tsec/d/60 25 | pace <- paste0(floor(pace), ":", round0((pace-floor(pace))*60), " min/km") 26 | speed <- paste(round(d/tsec*60*60,1), "km/h") 27 | message(d, " km in ", t, ", ", pace, " = ", speed) 28 | # Output: 29 | return(invisible(list(distance=d, time=t, seconds=tsec, pace=pace, speed))) 30 | } 31 | 32 | -------------------------------------------------------------------------------- /R/seqR.R: -------------------------------------------------------------------------------- 1 | #' seq with a range argument 2 | #' 3 | #' sequence given by range or vector of values. 4 | #' 5 | #' @return Numeric vector. 6 | #' @author Berry Boessenkool, \email{berry-b@@gmx.de}, Feb 2014 7 | #' @seealso \code{\link{seq}}, \code{\link{range}}, 8 | #' \url{https://web.archive.org/web/20190107005108/https://r.789695.n4.nabble.com/seq-range-argument-td4684627.html} 9 | #' @keywords datagen 10 | #' @importFrom grDevices extendrange 11 | #' @importFrom utils tail 12 | #' @export 13 | #' @examples 14 | #' 15 | #' seqR(range=c(12,6), by=-2) 16 | #' m <- c(41, 12, 38, 29, 50, 39, 22) 17 | #' seqR(m, len=6) 18 | #' # Takes min and max of range if the vector has more than two elements. 19 | #' 20 | #' seqR(range=c(12,6), by=-2, extend=0.1) 21 | #' # internaly calls extendrange with f=extend 22 | #' 23 | #' @param range vector with 2 values (1st taken as \code{from}, 2nd as \code{to}) 24 | #' or more (the result is then always ascending). 25 | #' @param from start value of sequence. DEFAULT: NA (determined from range) 26 | #' @param to end value of sequence. DEFAULT: NA (determined from range) 27 | #' @param extend Factor \emph{f} passed to \code{\link{extendrange}}. DEFAULT: 0 28 | #' @param warn Logical: warn about non-numeric classes? DEFAULT: TRUE 29 | #' @param \dots further arguments passed to \code{\link{seq}}. 30 | #' 31 | seqR <- function( 32 | range, 33 | from=NA, 34 | to=NA, 35 | extend=0, 36 | warn=TRUE, 37 | ...) 38 | { 39 | # only set from and to if range is given as input: 40 | if(!missing(range)) 41 | { 42 | # Input checking: 43 | if(!is.numeric(range) & warn) warning("'range' is not numeric, but ", 44 | toString(class(range)),".") 45 | # accept long vectors: 46 | if(length(range)>2) range <- base::range(range, na.rm=TRUE) 47 | # actual work: 48 | range <- extendrange(r=range, f=extend) 49 | from <- range[1] # first 50 | to <- tail(range,1) # and last value 51 | } 52 | # now call seq with from and to (obtained from range) 53 | seq(from=from, to=to, ...) 54 | } 55 | -------------------------------------------------------------------------------- /R/smoothLines.R: -------------------------------------------------------------------------------- 1 | #' draw smoothed lines 2 | #' 3 | #' draw smoothed lines with an n-level partially transparent haze 4 | #' 5 | #' @return none, draws lines 6 | #' @author Berry Boessenkool, \email{berry-b@@gmx.de}, 2011/2012 7 | #' @seealso \code{\link{lines}}, \code{\link{col2rgb}}, \code{\link{rgb}} 8 | #' @keywords aplot 9 | #' @importFrom graphics lines 10 | #' @export 11 | #' @examples 12 | #' 13 | #' x <- 1:5 ; y <- c(0.31, 0.45, 0.84, 0.43, 0.25) 14 | #' plot(x,y) 15 | #' smoothLines(x,y) 16 | #' #png("smoothLines.png") 17 | #' par(mar=c(2,2,2,0)+.5) 18 | #' plot(1:100, las=1, type="n", main="usage of smoothLines(x,y, lwd, col, n, alpha ...)") 19 | #' abline(h=0:10*10, v=0:10*10, col=6); box() 20 | #' for(i in 0:9) { smoothLines(x=c(0,10,25,35), y=c(i*10, i*10, i*10+12, i*10+7), lwd=i) 21 | #' text(25, i*10+5, paste("n=5,lwd=", i, sep="")) } 22 | #' for(i in 0:9) { smoothLines(x=c(40,50,65,75), y=c(i*10, i*10, i*10+12, i*10+7), n=i) 23 | #' text(65, i*10+5, paste("n=",i,",lwd=1", sep="")) } 24 | #' for(i in 0:9/20) { smoothLines(x=c(80,90,105), y=c(i*200, i*200+12, i*200+12), alpha=i) 25 | #' text(90, i*200+10, paste("alpha=", i, sep=""), adj=0) } 26 | #' text(5,10, "default", adj=c(0.5,-0.2)); text(45,50, "default", adj=c(0.5,-0.2)) 27 | #' 28 | #' #dev.off() 29 | #' 30 | #' @param x numerical. x-coordinates. x can be a matrix, then the y coordinates are taken from the second column 31 | #' @param y numerical. y-coordinates 32 | #' @param lwd single integer. line width 33 | #' @param col color. DEFAULT: 1 (black) 34 | #' @param n single integer. number of transparent lines overlayed with sinking line widths. DEFAULT: 5 35 | #' @param alpha Transparency of color. DEFAULT: 0.1 (very transparent) 36 | #' @param \dots further arguments as in \code{\link{lines}} 37 | #' 38 | smoothLines <- function( 39 | x, 40 | y, 41 | lwd=1, 42 | col=1, 43 | n=5, 44 | alpha=0.1, 45 | ...) 46 | { 47 | # Handling for Vector and Matrix with columns x and y 48 | if(is.vector(x)) {x <- x; y <- y} else {y <- x[,2]; x <- x[,1]} 49 | # plot transparent lines above each other 50 | for(i in 1:n) {lines(x,y, col=addAlpha(col, alpha=alpha), lwd=lwd+n+1-i, ...) } 51 | # add the original line above the rest 52 | lines(x,y, col=col, lwd=lwd, ...) 53 | } # end of function 54 | -------------------------------------------------------------------------------- /R/sortDF.R: -------------------------------------------------------------------------------- 1 | #' sort dataframes by column 2 | #' 3 | #' sort a data.frame by column - basically just a wrapper for order 4 | #' 5 | #' @return data.frame 6 | #' @author Berry Boessenkool, \email{berry-b@@gmx.de}, June 2015 7 | #' @seealso \code{\link{sort}}, \code{\link{order}}, 8 | #' \code{\link{insertRows}}, \code{\link{addRows}} 9 | #' @keywords univar manip arith 10 | #' @export 11 | #' @examples 12 | #' sortDF(USArrests[USArrests$Murder>11,], Assault) 13 | #' sortDF(USArrests[USArrests$Murder>11,], "Assault") # safer within functions 14 | #' sortDF(USArrests[USArrests$Murder>11,], 3) 15 | #' 16 | #' @param df Data.frame to be sorted 17 | #' @param col Column (index or (un)quoted name) to be sorted by 18 | #' @param decreasing Logical: should highest value be on top? 19 | #' DEFAULT: TRUE (unlike \code{\link{order}}!) 20 | #' @param quiet Logical: suppress non-df warning? DEFAULT: FALSE 21 | #' @param \dots Further arguments passed to \code{\link{order}}, 22 | #' like eg \code{na.last or method} 23 | #' 24 | sortDF <- function( 25 | df, 26 | col, 27 | decreasing=TRUE, 28 | quiet=FALSE, 29 | ... 30 | ) 31 | { 32 | values <- getColumn(substitute(col),df, quiet=quiet) 33 | df[order(values, decreasing=decreasing, ...),] 34 | } 35 | -------------------------------------------------------------------------------- /R/sumatraPaths.R: -------------------------------------------------------------------------------- 1 | #' @title Get Sumatra PDF Viewer paths 2 | #' @description 3 | #' Get Sumatra paths for \code{\link{sumatraInitialize}}. This will only work on windows. 4 | #' @return paths 5 | #' @author Berry Boessenkool, \email{berry-b@@gmx.de}, Jan 2024 6 | #' @seealso \code{\link{sumatraInitialize}} 7 | #' @export 8 | #' @examples 9 | #' sumatraPaths() 10 | #' @param open open the folders? DEFAULT: FALSE 11 | #' 12 | sumatraPaths <- function(open=FALSE) 13 | { 14 | if(.Platform$OS.type != "windows") stop("SumatraPDF is only available on Windows") 15 | # Exe path: 16 | epath <- Sys.getenv("RSTUDIO_DESKTOP_EXE") 17 | epath <- normalizePathCP(epath) 18 | epath <- sub("rstudio.exe$", "resources/app/bin/sumatra", epath) 19 | # Roampath 20 | rpath <- Sys.getenv("APPDATA") 21 | rpath <- normalizePathCP(rpath) 22 | rpath <- paste0(rpath, "/SumatraPDF") 23 | # open: 24 | if(open) openFile(epath) 25 | if(open) openFile(rpath) 26 | # Output: 27 | return(c(epath, rpath)) 28 | } 29 | -------------------------------------------------------------------------------- /R/timer.R: -------------------------------------------------------------------------------- 1 | #' Timer alarm 2 | #' 3 | #' Beeps in a given interval and gives a progress bar in the console 4 | #' 5 | #' @details defaults to practice useR lightning talks: 15 slides, each shown 20 secs, change automatically 6 | #' 7 | #' @return none 8 | #' @author Berry Boessenkool, \email{berry-b@@gmx.de}, June 2015 9 | #' @seealso \code{\link{alarm}}, \code{\link{Sys.sleep}}, \code{\link{txtProgressBar}} 10 | #' @references \url{https://user2015.math.aau.dk/lightning_talks} 11 | #' @keywords utilities chron 12 | #' @importFrom utils alarm setTxtProgressBar txtProgressBar 13 | #' @export 14 | #' @examples 15 | #' 16 | #' \dontrun{## Skip time consuming checks on CRAN 17 | #' timer(interval=0.5, n=3) 18 | #' timer(interval=0.2, n=8, write=TRUE) # a slight deviation occurs for a large n 19 | #' # timer() # to practice lightning talks at useR! conferences 20 | #' } 21 | #' 22 | #' @param interval \code{\link{alarm}} interval in seconds. DEFAULT: 20 23 | #' @param n number of alarm signals to be given. DEFAULT: 15 24 | #' @param write Should the actual estimated time be written for overhead computing time control purposes? DEFAULT: FALSE 25 | #' 26 | timer <- function( 27 | interval=20, 28 | n=15, 29 | write=FALSE 30 | ) 31 | { 32 | begin <- Sys.time() 33 | pb <- txtProgressBar(max=n, style=3) 34 | for(i in 1:n) 35 | { 36 | Sys.sleep(interval) 37 | setTxtProgressBar(pb, i) 38 | alarm() 39 | } 40 | close(pb) 41 | time_used <- round(difftime(Sys.time(), begin, units="secs"), 2) 42 | if(write) message("Actual time passed by: ", time_used, 43 | " secs. Deviance from target: ", round(time_used-interval*n, 2), 44 | " (", round((time_used-interval*n)/(interval*n)*100, 2), "%).") 45 | } 46 | 47 | # Examples: 48 | # timer(interval=1, n=3) 49 | # timer(interval=0.2, n=15, write=TRUE) 50 | # timer() # to practice lightning talks at useR! conferences 51 | -------------------------------------------------------------------------------- /R/tmessage.R: -------------------------------------------------------------------------------- 1 | #' @title messages with call trace 2 | #' @description [message], [warning] or [stop] with a call trace prepended 3 | #' @md 4 | #' @param ... Passed to [message], [warning] or [stop] 5 | #' @param skip Number of tracing levels to exclude. Default: 0 6 | #' @param call. include twarning/tstop call? DEFAULT: FALSE (unlike the originals) 7 | #' @param noBreaks. reduce line breaks if `options(warn=1)`? 8 | #' DEFAULT: TRUE (unlike the original) 9 | #' @aliases tmessage twarning tstop 10 | #' @return NULL, as per [message], [warning] or [stop] 11 | #' @export 12 | #' @seealso [traceCall] for the generation of the trace 13 | #' @examples 14 | #' lower <- function(a, s) {tmessage("some stuff with ", a+10, skip=s); a} 15 | #' upper <- function(b, skip=0) lower(b+5, skip) 16 | #' upper(3) # upper -> lower: some stuff with 18 17 | #' upper(3, skip=1) # no "lower" in trace 18 | #' upper(3, skip=-1) # upper -> lower -> tmessage: some stuff with 18 19 | #' tmessage("Some message", " to be displayed") 20 | #' lower <- function(a, s) {twarning("some stuff with ", a+10, skip=s); a} 21 | #' upper(7) 22 | #' oop <- options(warn=1) 23 | #' upper(7) # Warning: upper -> lower: some [] no line break :) 24 | #' options(oop) ; rm(oop) 25 | #' lower <- function(a, s) {tstop("some stuff with ", a+10, skip=s); a} 26 | #' try( upper(7) ) # Error : try -> upper -> lower: some stuff with 22 27 | 28 | tmessage <- function(..., skip=0) 29 | { 30 | x <- traceCall(skip=skip+1, prefix="", suffix=": ") 31 | message(x, ...) 32 | } 33 | 34 | #' @rdname tmessage 35 | #' @export 36 | twarning <- function(..., skip=0, call.=FALSE, noBreaks.=TRUE) 37 | { 38 | x <- traceCall(skip=skip+1, prefix="", suffix=": ") 39 | warning(x, ..., call.=call., noBreaks.=noBreaks.) 40 | } 41 | 42 | #' @rdname tmessage 43 | #' @export 44 | tstop <- function(..., skip=0, call.=FALSE) 45 | { 46 | x <- traceCall(skip=skip+1, prefix="", suffix=": ") 47 | stop(x, ..., call.=call.) 48 | } 49 | -------------------------------------------------------------------------------- /R/truncMessage.R: -------------------------------------------------------------------------------- 1 | #' truncate message parts 2 | #' 3 | #' truncate long vectors for messages 4 | #' 5 | #' @return Character string 6 | #' @author Berry Boessenkool, \email{berry-b@@gmx.de}, Nov 2016 7 | #' @seealso \code{\link{message}} 8 | #' @keywords character 9 | # @importFrom package fun1 fun2 10 | #' @export 11 | #' @examples 12 | #' truncMessage("hi") 13 | #' message("listing name", truncMessage( "hi" ), ".") 14 | #' message("listing name", truncMessage(paste0("hi",1:10)), ".") 15 | #' truncMessage(paste0("hi",1:10), ntrunc=1) 16 | #' truncMessage(paste0("hi",1:10), ntrunc=2, prefix="", midfix="") 17 | #' truncMessage(paste0("hi",1:10), ntrunc=8, prefix="files _ ") 18 | #' 19 | #' @param x Character vector 20 | #' @param ntrunc Integer: number of elements printed before truncation. DEFAULT: 3 21 | #' @param prefix Character: Prefix added if \code{length(x)>1}. DEFAULT: "s" 22 | #' @param midfix Character: string added after prefix OR before first altnix. DEFAULT: " " 23 | #' @param altnix Character: Alternative string padded around x if \code{length(x)==1}. 24 | #' DEFAULT: "'" 25 | #' @param sep Character: Separator between elements. DEFAULT: ", " 26 | #' 27 | truncMessage <- function( 28 | x, 29 | ntrunc=3, 30 | prefix="s", 31 | midfix=" ", 32 | altnix="'", 33 | sep=", " 34 | ) 35 | { 36 | l <- length(x) 37 | if(l>ntrunc) x <- x[1:ntrunc] 38 | paste0(if(l>1) paste0(prefix,midfix) else paste0(midfix,altnix), paste0(x, collapse=sep), 39 | if(l>ntrunc) paste(if(!missing(sep)) sep, " (and",l-ntrunc,"more)"), if(l==1) altnix) 40 | } 41 | -------------------------------------------------------------------------------- /R/write.tab.R: -------------------------------------------------------------------------------- 1 | #' @title write table with different defaults 2 | #' @description calls write.table with (personally) useful default values for the arguments. 3 | #' if \code{open=TRUE}, tries to open the file in the default txt viewer. 4 | #' @return full filename 5 | #' @author Berry Boessenkool, \email{berry-b@@gmx.de}, Sep 2021 6 | #' @seealso \code{\link{write.tab}} 7 | #' @keywords file 8 | #' @importFrom utils write.table 9 | #' @export 10 | #' @examples 11 | #' # Don't run on CRAN test machines: 12 | #' \dontrun{ 13 | #' write.tab(iris) 14 | #' write.tab(iris, "otherfile.txt") 15 | #' write.tab(freeny) 16 | #' write.tab(freeny, name_rn="Time") 17 | #' unlink("iris.txt") 18 | #' unlink("otherfile.txt") 19 | #' unlink("freeny.txt") 20 | #' } 21 | #' @param x Objekt to be written. 22 | #' @param file Filename. DEFAULT: NULL = [name of x].txt 23 | #' @param quote Write quatation marks around charstrings? DEFAULT: FALSE 24 | #' @param sep Column separator. DEFAULT: "\\t" 25 | #' @param name_rn If not NULL, this will be used as the name for a prepended 26 | #' column with the rownames. DEFAULT: NULL 27 | #' @param row.names Should rownames be written in a pre-column that will 28 | #' mess up alignment with column names? 29 | #' Use \code{name_rn} instead. DEFAULT: FALSE 30 | #' @param col.names Should colnames be written? 31 | #' DEFAULT: TRUE if x has colnames 32 | #' @param fileEncoding Encoding of charstrings. DEFAULT: "UTF-8" 33 | #' @param open Try to open the output file? DEFAULT: TRUE 34 | #' @param \dots Further arguments passed to \code{\link{write.table}} 35 | #' 36 | write.tab <- function( 37 | x, 38 | file=NULL, 39 | sep="\t", 40 | name_rn=NULL, 41 | row.names=FALSE, 42 | col.names=!is.null(colnames(x)), 43 | quote=FALSE, 44 | fileEncoding="UTF-8", 45 | open=TRUE, 46 | ... 47 | ) 48 | { 49 | if(is.null(file)) file <- paste0(deparse(substitute(x)), ".txt") 50 | if(!is.null(name_rn)) {x <- cbind(rownames(x), x) ; colnames(x)[1] <- name_rn} 51 | write.table(x=x, file=file, sep=sep, row.names=row.names, col.names=col.names, 52 | quote=quote, fileEncoding=fileEncoding, ...) 53 | if(open) openFile(file) 54 | return(normalizePath(file, winslash="/")) 55 | } 56 | -------------------------------------------------------------------------------- /R/yearSample.R: -------------------------------------------------------------------------------- 1 | #' Nonrandom year with sample 2 | #' 3 | #' Nerdy way to wish someone a happy new year by using sample 4 | #' 5 | #' @details Nerdy way to wish someone a happy new year, eg:\cr 6 | #' Have a great \cr 7 | #' \code{set.seed(1244); sample(0:9,4,T)} 8 | #' 9 | #' @return \code{\link{cat}}s command into the console that can be copypasted to anyone's R script. 10 | #' @author Berry Boessenkool, \email{berry-b@@gmx.de}, April 2014 11 | #' @seealso \code{\link{nameSample}} to impress with "randomly" finding a name, 12 | #' \code{\link{set.seed}}, \code{\link{sample}}, \code{\link{letters}} 13 | #' @export 14 | #' @examples 15 | #' 16 | #' yearSample(2016) 17 | #' # Have a nerdy 18 | #' set.seed(12353); sample(0:9, 4, replace=TRUE) 19 | #' 20 | #' @param year 4 digit numerical year. 21 | #' 22 | yearSample <- function( 23 | year 24 | ) 25 | { 26 | year2 <- as.numeric(substring(year, first=1:4, last=1:4)) 27 | year_is_false <- function(i) 28 | { 29 | set.seed(i) 30 | any( sample(0:9, 4, replace=TRUE) != year2 ) 31 | } 32 | i <- 0 33 | while( year_is_false(i) ) i <- i+1 34 | output <- paste0("set.seed(", i, "); sample(0:9,4,T)\n") 35 | message(output) 36 | } 37 | 38 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ### intro 2 | 3 | Miscellaneous R functions. Notable: colPoints, horizHist, logAxis, pointZoom, smallPlot, lsc. 4 | 5 | **See the [Vignette](https://cran.r-project.org/package=berryFunctions/vignettes/berryFunctions.html) for an overview of the package.** 6 | 7 | [Recent changes](https://starlogs.dev/brry/berryFunctions) (Thanks, [Jenny](https://happygitwithr.com/comic-relief.html)) 8 | 9 | 10 | ### installation 11 | Install release version from CRAN: 12 | [![CRAN_Status_Badge](https://www.r-pkg.org/badges/version-last-release/berryFunctions)](https://cran.r-project.org/package=berryFunctions) 13 | [![downloads](https://cranlogs.r-pkg.org/badges/berryFunctions)](https://www.r-pkg.org/services) 14 | [![Rdoc](https://www.rdocumentation.org/badges/version/berryFunctions)](https://www.rdocumentation.org/packages/berryFunctions) 15 | !["berryFunctions dependencies"](https://tinyverse.netlify.com/badge/berryFunctions) 16 | 17 | 18 | ```R 19 | install.packages("berryFunctions") 20 | library(berryFunctions) 21 | vignette("berryFunctions") 22 | ?berryFunctions 23 | ``` 24 | 25 | Update to the [current development version](https://github.com/brry/berryFunctions/blob/master/DESCRIPTION#L4-L5) 26 | on github: 27 | : 28 | ```R 29 | if(!requireNamespace("remotes", quitly=TRUE)) install.packages("remotes") 30 | remotes::install_github("brry/berryFunctions") 31 | ``` 32 | 33 | ### trouble 34 | 35 | If direct installation from CRAN doesn't work, your R version might be too old. In that case, an update is really recommendable: [r-project.org](https://www.r-project.org/). If you can't update R, try installing from source (github) via `instGit` or devtools as mentioned above. If that's not possible either, here's a manual workaround: 36 | click on **Code - Download ZIP** (top right), unzip the file to some place, then 37 | ```R 38 | setwd("that/path") 39 | dd <- dir("berryFunctions-master/R", full=T) 40 | dummy <- sapply(dd, source) 41 | ``` 42 | This creates all R functions as objects in your globalenv workspace (and overwrites existing objects of the same name!). 43 | 44 | ### license 45 | 46 | This package is under the GPL license. 47 | I am fine with you doing whatever you want with it, provided that my name and credit remains attached to it. 48 | If you legally need a more permissive license, let me know and I can probably change it. 49 | -------------------------------------------------------------------------------- /Tests.R: -------------------------------------------------------------------------------- 1 | 2 | # Function development testing 3 | # Berry Boessenkool, started Oct 2016 4 | 5 | # colPointsLegend potentially extremely dependent on graphics size. 6 | # may also require changes in smallPlot 7 | 8 | # example comment to show off git 9 | 10 | 11 | i <- c( 22, 40, 48, 60, 80, 70, 70, 63, 55, 48, 45, 40, 30, 32) 12 | j <- c( 5, 10, 15, 20, 12, 30, 45, 40, 30, 36, 56, 33, 45, 23) 13 | k <- c(175, 168, 163, 132, 120, 117, 110, 130, 131, 160, 105, 174, 190, 183) 14 | 15 | for(hh in c(400,350,300)) 16 | { 17 | png(paste0("test",hh,".png"), width=800, height=hh) 18 | tryStack(colPoints(i,j,k, cex=1.5, pch="+", add=FALSE)) 19 | dev.off() 20 | } 21 | unlink(paste0("test",c(400,350,300),".png")) 22 | 23 | 24 | # smallPlot 25 | 26 | owd <- setwd(desktop) 27 | for(i in 1:2) { 28 | if(i==1) pdf("margtest_1.pdf") else pdf("margtest_2.pdf", height=5) 29 | plot(1:100, xlab=toString(letters)) 30 | smallPlot(plot(5:1, ylab="Yo man!"), x1=0.0,x2=0.5, y1=0.2,y2=0.9, bg="lightblue") 31 | smallPlot(plot(5:1, ylab="Yo man-"), x1=0.0,x2=0.5, y1=0.2,y2=0.9, bg=addAlpha(2), outer=TRUE) 32 | smallPlot(plot(5:1, ylab="Yo man!"), x1=0.0,x2=0.7, y1=0.2,y2=0.5, bg="transparent") 33 | smallPlot(plot(5:1), x1=0.5,x2= 1, y1=0.5,y2= 1, bg="lightblue") 34 | smallPlot(plot(5:1), x1=0.5,x2=0.8, y1=0.5,y2=0.8, bg=addAlpha(2)) 35 | dev.off() 36 | } 37 | setwd(owd) 38 | rm(i,owd) 39 | 40 | 41 | -------------------------------------------------------------------------------- /cran-comments.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brry/berryFunctions/f3bb278492793144ffaad0b9cc488f44a11cae00/cran-comments.md -------------------------------------------------------------------------------- /funs.odt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brry/berryFunctions/f3bb278492793144ffaad0b9cc488f44a11cae00/funs.odt -------------------------------------------------------------------------------- /inst/extdata/Anhang.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brry/berryFunctions/f3bb278492793144ffaad0b9cc488f44a11cae00/inst/extdata/Anhang.pdf -------------------------------------------------------------------------------- /inst/extdata/Rlogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brry/berryFunctions/f3bb278492793144ffaad0b9cc488f44a11cae00/inst/extdata/Rlogo.png -------------------------------------------------------------------------------- /inst/extdata/SumatraPDF-settings.txt: -------------------------------------------------------------------------------- 1 | # For documentation, see https://www.sumatrapdfreader.org/settings/settings 2 | 3 | RestoreSession = true 4 | RememberOpenedFiles = true 5 | RememberStatePerDocument = true 6 | 7 | ReloadModifiedDocuments = true 8 | FullPathInTitle = false 9 | ShowMenubar = true 10 | ShowToolbar = true 11 | ShowToc = false 12 | ShowFavorites = false 13 | 14 | DefaultDisplayMode = single page 15 | DefaultZoom = fit page 16 | WindowState = 1 17 | WindowPos = 0 0 0 0 18 | ShowStartPage = true 19 | UseTabs = true 20 | -------------------------------------------------------------------------------- /inst/extdata/Temp.txt: -------------------------------------------------------------------------------- 1 | # Temperature Decline in Mug 2 | Minuten Temp 3 | 0 74,5 4 | 0,5 73,6 5 | 1 73,0 6 | 1,5 72,4 7 | 2 71,1 8 | 2,5 70,7 9 | 3 70,1 10 | 3,5 69,1 11 | 4 68,3 12 | 4,5 68,0 13 | 5 67,2 14 | 5,5 66,3 15 | 6 65,9 16 | 6,5 65,3 17 | 7 64,7 18 | 7,5 64,0 19 | 8 63,1 20 | 8,5 62,6 21 | 9 61,6 22 | 9,5 NA 23 | 10 60,5 24 | 10,5 60,0 25 | 11 59,5 26 | 11,5 59,0 27 | 12 58,7 28 | 12,5 58,3 29 | 13 57,6 30 | 13,5 57,2 31 | 14 56,5 32 | 14,5 56,1 33 | 15 55,4 34 | 15,5 55,0 35 | 16 54,8 36 | 16,5 54,3 37 | 17 53,9 38 | 17,5 53,4 39 | 18 53,2 40 | 18,5 52,6 41 | 19 52,2 42 | 19,5 51,8 43 | 20 51,4 44 | 20,5 51,0 45 | 21 51,0 46 | 21,5 50,5 47 | 22 50,4 48 | 22,5 49,8 49 | 23 49,5 50 | 23,5 49,1 51 | 24 48,7 52 | 24,5 48,4 53 | 25 48,1 54 | 25,5 47,7 55 | 26 47,4 56 | 26,5 47,1 57 | 27 46,8 58 | 27,5 46,5 59 | 28 46,2 60 | 28,5 45,9 61 | 29 45,6 62 | 29,5 45,3 63 | 30 45,0 64 | 30,5 44,8 65 | 31 44,5 66 | 31,5 44,3 67 | 32 44,0 68 | 32,5 43,8 69 | 33 43,6 70 | 33,5 43,3 71 | 34 43,1 72 | 34,5 42,9 73 | 35 42,6 74 | 35,5 42,4 75 | 36 42,2 76 | 36,5 42,0 77 | 37 41,8 78 | 37,5 41,6 79 | 38 41,3 80 | 38,5 41,1 81 | 39 40,9 82 | 39,5 40,7 83 | 40 40,5 84 | 45 38,7 85 | 50 37,1 86 | 55 35,7 87 | 60 34,4 88 | 65 33,2 89 | 70 32,2 90 | 90 29,0 91 | 115 26,8 92 | 120 26,5 93 | 140 25,3 94 | 95 | -------------------------------------------------------------------------------- /inst/extdata/calctime_nameSample.txt: -------------------------------------------------------------------------------- 1 | "x" 2 | "c.elapsed" 0.00200000000040745 3 | "k.elapsed" 0.00199999999949796 4 | "f.elapsed" 0 5 | "o.elapsed" 0.00100000000020373 6 | "d.elapsed" 0.00100000000020373 7 | "g.elapsed" 0 8 | "a.elapsed" 0.00100000000020373 9 | "h.elapsed" 0 10 | "j.elapsed" 0.00200000000040745 11 | "l.elapsed" 0.000999999999294232 12 | "b.elapsed" 0 13 | "n.elapsed" 0.00100000000020373 14 | "i.elapsed" 0.000999999999294232 15 | "m.elapsed" 0.000999999999294232 16 | "e.elapsed" 0.00100000000020373 17 | "lf.elapsed" 0.00100000000020373 18 | "jc.elapsed" 0.00799999999981083 19 | "do.elapsed" 0.00299999999970169 20 | "nb.elapsed" 0.00900000000001455 21 | "mi.elapsed" 0.00299999999970169 22 | "gl.elapsed" 0.011000000000422 23 | "fn.elapsed" 0.0379999999995562 24 | "ie.elapsed" 0.0159999999996217 25 | "cd.elapsed" 0.0230000000001382 26 | "hk.elapsed" 0.0450000000000728 27 | "ej.elapsed" 0.0419999999994616 28 | "bh.elapsed" 0.00500000000010914 29 | "ka.elapsed" 0.00100000000020373 30 | "om.elapsed" 0.00299999999970169 31 | "ag.elapsed" 0.0180000000000291 32 | "bee.elapsed" 0.206000000000131 33 | "mno.elapsed" 0.648000000000138 34 | "hcb.elapsed" 0.0409999999992579 35 | "nid.elapsed" 1.13500000000022 36 | "ohg.elapsed" 1.24399999999969 37 | "egc.elapsed" 1.0659999999998 38 | "lmi.elapsed" 0.345000000000255 39 | "aah.elapsed" 0.0900000000001455 40 | "fkk.elapsed" 1.40400000000045 41 | "ifm.elapsed" 0.179000000000087 42 | "cjj.elapsed" 0.117999999999483 43 | "gbl.elapsed" 0.557999999999993 44 | "dla.elapsed" 0.485999999999876 45 | "jdn.elapsed" 0.355999999999767 46 | "kof.elapsed" 0.820999999999913 47 | "bman.elapsed" 9.25799999999981 48 | "mgdd.elapsed" 29.4989999999998 49 | "gdbe.elapsed" 48.433 50 | "jila.elapsed" 0.960000000000036 51 | "acki.elapsed" 10.4970000000003 52 | "nojc.elapsed" 47.768 53 | "elij.elapsed" 56.6110000000008 54 | "cbco.elapsed" 21.8209999999999 55 | "hegl.elapsed" 16.4660000000003 56 | "oahb.elapsed" 56.2619999999997 57 | "ihek.elapsed" 13.8449999999993 58 | "kjmm.elapsed" 8.36299999999937 59 | "fnff.elapsed" 8.89800000000014 60 | "dfnh.elapsed" 0.838999999999942 61 | "lkog.elapsed" 10.723 62 | -------------------------------------------------------------------------------- /inst/extdata/calctime_nameSample2.txt: -------------------------------------------------------------------------------- 1 | "x" 2 | "c.elapsed" 0 3 | "a.elapsed" 0 4 | "i.elapsed" 0 5 | "l.elapsed" 0 6 | "k.elapsed" 0 7 | "b.elapsed" 0 8 | "d.elapsed" 0 9 | "f.elapsed" 0 10 | "e.elapsed" 0 11 | "m.elapsed" 0 12 | "o.elapsed" 0 13 | "g.elapsed" 0 14 | "h.elapsed" 0 15 | "j.elapsed" 0 16 | "n.elapsed" 0 17 | "ce.elapsed" 0 18 | "mc.elapsed" 0 19 | "el.elapsed" 0 20 | "ga.elapsed" 0.00999999999999091 21 | "ff.elapsed" 0 22 | "bd.elapsed" 0 23 | "kj.elapsed" 0 24 | "do.elapsed" 0 25 | "ag.elapsed" 0.00999999999999091 26 | "hk.elapsed" 0.0299999999999727 27 | "oi.elapsed" 0 28 | "nb.elapsed" 0 29 | "jm.elapsed" 0 30 | "in.elapsed" 0.0199999999999818 31 | "lh.elapsed" 0 32 | "nbg.elapsed" 0.0899999999999181 33 | "ohe.elapsed" 0.230000000000018 34 | "elh.elapsed" 0.0799999999999272 35 | "fcf.elapsed" 0.2199999999998 36 | "gkb.elapsed" 0.449999999999818 37 | "hom.elapsed" 0.680000000000064 38 | "keo.elapsed" 0.150000000000091 39 | "bjk.elapsed" 0.3599999999999 40 | "cad.elapsed" 0.0500000000001819 41 | "iil.elapsed" 0.440000000000055 42 | "mna.elapsed" 0.0199999999999818 43 | "dfi.elapsed" 0.1099999999999 44 | "adc.elapsed" 0.309999999999945 45 | "jgn.elapsed" 0.0199999999999818 46 | "lmj.elapsed" 0.0199999999999818 47 | "gnhi.elapsed" 13.01 48 | "maoe.elapsed" 14.8 49 | "fjcm.elapsed" 15.0700000000002 50 | "ocbc.elapsed" 0.940000000000055 51 | "aifa.elapsed" 6.74000000000001 52 | "egjg.elapsed" 1.5 53 | "jfkb.elapsed" 2.98000000000002 54 | "chid.elapsed" 1.59999999999991 55 | "nemf.elapsed" 6.77999999999997 56 | "ikel.elapsed" 11.3099999999999 57 | "hbdh.elapsed" 0.759999999999991 58 | "koaj.elapsed" 16.3800000000001 59 | "blnn.elapsed" 0.919999999999845 60 | "lmlo.elapsed" 3.15000000000009 61 | "ddgk.elapsed" 11.9300000000001 62 | -------------------------------------------------------------------------------- /inst/extdata/camera.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brry/berryFunctions/f3bb278492793144ffaad0b9cc488f44a11cae00/inst/extdata/camera.pptx -------------------------------------------------------------------------------- /inst/extdata/camera1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brry/berryFunctions/f3bb278492793144ffaad0b9cc488f44a11cae00/inst/extdata/camera1.jpg -------------------------------------------------------------------------------- /inst/extdata/camera2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brry/berryFunctions/f3bb278492793144ffaad0b9cc488f44a11cae00/inst/extdata/camera2.png -------------------------------------------------------------------------------- /inst/extdata/ccby.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brry/berryFunctions/f3bb278492793144ffaad0b9cc488f44a11cae00/inst/extdata/ccby.png -------------------------------------------------------------------------------- /inst/extdata/doublelines.txt: -------------------------------------------------------------------------------- 1 | double lines 2 | to test dupes 3 | 4 | this is a file 5 | with spaces in this line 6 | with spaces in this line 7 | with spaces in this line 8 | with spaces in this line too, but only exact matches are analysed 9 | to test dupes 10 | which is 11 | 12 | a function in my misc package berryFunctions 13 | to find duplicate lines in a text file 14 | and color them accordingly 15 | in excel or libreOffice 16 | using conditional formatting 17 | -------------------------------------------------------------------------------- /inst/extdata/dupes.ods: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brry/berryFunctions/f3bb278492793144ffaad0b9cc488f44a11cae00/inst/extdata/dupes.ods -------------------------------------------------------------------------------- /inst/extdata/gelman_equation_search.txt: -------------------------------------------------------------------------------- 1 | y x1 x2 2 | 15.68 6.87 14.09 3 | 6.18 4.4 4.35 4 | 18.1 0.43 18.09 5 | 9.07 2.73 8.65 6 | 17.97 3.25 17.68 7 | 10.04 5.3 8.53 8 | 20.74 7.08 19.5 9 | 9.76 9.73 0.72 10 | 8.23 4.51 6.88 11 | 6.52 6.4 1.26 12 | 15.69 5.72 14.62 13 | 15.51 6.28 14.18 14 | 20.61 6.14 19.68 15 | 19.58 8.26 17.75 16 | 9.72 9.41 2.44 17 | 16.36 2.88 16.1 18 | 18.3 5.74 17.37 19 | 13.26 0.45 13.25 20 | 12.1 3.74 11.51 21 | 18.15 5.03 17.44 22 | 16.8 9.67 13.74 23 | 16.55 3.62 16.15 24 | 18.79 2.54 18.62 25 | 15.68 9.15 12.74 26 | 4.08 0.69 4.02 27 | 15.45 7.97 13.24 28 | 13.44 2.49 13.21 29 | 20.86 9.81 18.41 30 | 16.05 7.56 14.16 31 | 6 0.98 5.92 32 | 3.29 0.65 3.22 33 | 9.41 9 2.74 34 | 10.76 7.83 7.39 35 | 5.98 0.26 5.97 36 | 19.23 3.64 18.89 37 | 15.67 9.28 12.63 38 | 7.04 5.66 4.18 39 | 21.63 9.71 19.32 40 | 17.84 9.36 15.19 41 | 7.49 0.88 7.43 -------------------------------------------------------------------------------- /inst/extdata/mRegProblem.txt: -------------------------------------------------------------------------------- 1 | x y 2 | 5917495.183 10.32 3 | 5912487.368 9.72 4 | 5907569.907 4.97 5 | 5912733.363 5.69 6 | 5907299.869 7 7 | 5915597.224 8.78 8 | 5915777.942 11.3 9 | 5915984.39 6.58 10 | 5916298.587 6.71 11 | 5916301.93 4.83 12 | 5918361.196 8.2 13 | 5916026.573 14.94 14 | 5915913.67 15.43 15 | 5912708.48 12.88 16 | 5912708.48 13.72 17 | 5912267.59 11.9 18 | 5912267.59 12.45 19 | 5912391.72 14.53 20 | 5912391.72 16.31 21 | 5914397.16 13.03 22 | 5914397.16 16.7 23 | 5917416.01 13.36 24 | 5917416.01 15.52 25 | 5916330.37 29.4 26 | 5916330.37 23.27 27 | 5907839.12 12.97 28 | 5907839.12 13.29 29 | 5907369.89 36.16 30 | 5907369.89 36.26 31 | 5891834.6 21.81 32 | 5891834.6 23.2 33 | 5908886.66 14.53 34 | 5908886.66 14.31 35 | 5910415.93 17.1 36 | 5910415.93 17.58 37 | 5913404.07 16.51 38 | 5913404.07 16.49 39 | 5913090.52 15.6 40 | 5913090.52 16.41 41 | -------------------------------------------------------------------------------- /inst/extdata/mRegProblem2.txt: -------------------------------------------------------------------------------- 1 | x y 2 | 33408047.33 10.32 3 | 33408038.32 9.72 4 | 33403589.09 4.97 5 | 33408155.79 5.69 6 | 33403966.7 7 7 | 33413999.28 8.78 8 | 33413999.02 11.3 9 | 33414169.61 6.58 10 | 33419310.47 6.71 11 | 33419611.79 4.83 12 | 33410713.96 8.2 13 | 33418928.72 14.94 14 | 33419193.89 15.43 15 | 33412572.29 12.88 16 | 33412572.29 13.72 17 | 33409711.82 11.9 18 | 33409711.82 12.45 19 | 33410046.77 14.53 20 | 33410046.77 16.31 21 | 33408727.29 13.03 22 | 33408727.29 16.7 23 | 33410857.93 13.36 24 | 33410857.93 15.52 25 | 33426968.67 29.4 26 | 33426968.67 23.27 27 | 33421172.56 12.97 28 | 33421172.56 13.29 29 | 33423415.62 36.16 30 | 33423415.62 36.26 31 | 33420261.65 21.81 32 | 33420261.65 23.2 33 | 33422250.88 14.53 34 | 33422250.88 14.31 35 | 33420582.01 17.1 36 | 33420582.01 17.58 37 | 33419850.29 16.51 38 | 33419850.29 16.49 39 | 33417940.57 15.6 40 | 33417940.57 16.41 41 | -------------------------------------------------------------------------------- /inst/extdata/pmedians.txt: -------------------------------------------------------------------------------- 1 | 0.686056564294554 2 | 0.721701405706746 3 | 0.683711515798406 4 | 0.687872505696848 5 | 0.668445506751037 6 | 0.68061946509587 7 | 0.671300673168475 8 | 0.684860972042166 9 | 0.694282961525291 10 | 0.680530307680479 11 | 0.670778361079156 12 | 0.682470709019395 13 | 0.679633865193449 14 | 0.677801783051675 15 | 0.673748828134455 16 | 0.677578832401752 17 | 0.680419222614705 18 | 0.672659851664831 19 | 0.684226914462117 20 | 0.676675654607572 21 | 0.678502028205713 22 | 0.671528297236511 23 | 0.677667726186971 24 | 0.666653968162956 25 | 0.672918563221139 26 | 0.67684620602162 27 | 0.676744817484912 28 | 0.67513476165024 29 | 0.668885113353958 30 | 0.685682270348946 31 | -------------------------------------------------------------------------------- /inst/extdata/rivers.txt: -------------------------------------------------------------------------------- 1 | # Fake river network for colPoints 2 | x y n 3 | 2 5 21 4 | 9 13 20 5 | 11 22 19 6 | 11 34 18 7 | 16 41 18 8 | 24 45 16 9 | 31 48 16 10 | 38 53 12 11 | 40 59 12 12 | 39 69 11 13 | 36 78 10 14 | 28 87 9 15 | 24 91 8 16 | NA NA NA 17 | 9 13 20 18 | 11 9 18 19 | 18 10 17 20 | 25 10 15 21 | 42 11 14 22 | 51 13 13 23 | 63 12 11 24 | 88 11 9 25 | 97 9 8 26 | NA NA NA 27 | 51 13 13 28 | 54 19 7 29 | 58 32 6 30 | 58 38 5 31 | 59 42 4 32 | 62 47 3 33 | 74 54 1 34 | NA NA NA 35 | 16 41 18 36 | 15 50 5 37 | 9 57 2 38 | 6 62 1 39 | NA NA NA 40 | 39 69 11 41 | 43 76 6 42 | 53 78 5 43 | 64 79 5 44 | 74 79 1 45 | -------------------------------------------------------------------------------- /inst/extdata/versuch1.txt: -------------------------------------------------------------------------------- 1 | Das ist nur eine kleine Testdatei. 2 | Mit einer Leerzeile folgend: 3 | 4 | Damit reichts dann auch. 5 | Und der Versuch, keinen letzten Zeilenumbruch zu haben geht schief bei readLines. -------------------------------------------------------------------------------- /inst/extdata/versuch2.txt: -------------------------------------------------------------------------------- 1 | Das ist nur eine kleine Testdatei. 2 | Dies ist die zweite Testdatei. 3 | 4 | Damit reichts dann auch. 5 | Tschau. 6 | -------------------------------------------------------------------------------- /man/TFtest.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/TFtest.R 3 | \name{TFtest} 4 | \alias{TFtest} 5 | \title{Test logical expressions} 6 | \usage{ 7 | TFtest(..., na = TRUE) 8 | } 9 | \arguments{ 10 | \item{\dots}{Expression(s) with logical operators to be evaluated, 11 | with single letters for variables. Each expression is to be separated with a comma} 12 | 13 | \item{na}{Logical: should NAs be included in the truth table? DEFAULT: TRUE} 14 | } 15 | \value{ 16 | Truth table as data.frame with TRUE and FALSE (and NA) combinations 17 | } 18 | \description{ 19 | Check if logical expressions return what you expect with a truth table 20 | } 21 | \details{ 22 | This is a nice way to check operator precedence, see \code{\link{Syntax}} 23 | } 24 | \examples{ 25 | TFtest(!a & !b) 26 | TFtest(!a & !b, a&b, !(a&b)) 27 | TFtest(!a & !b | c) 28 | TFtest(!a & !b | c, na=FALSE) 29 | TFtest(!a) 30 | TFtest(a&b|c, (a&b)|c, a&(b|c), na=FALSE) # AND has precedence over OR 31 | TFtest(a|b, xor(a,b), na=FALSE) 32 | 33 | } 34 | \seealso{ 35 | \code{\link{logical}} 36 | } 37 | \author{ 38 | Berry Boessenkool, \email{berry-b@gmx.de}, Mrz 2016 39 | } 40 | \keyword{logic} 41 | -------------------------------------------------------------------------------- /man/addAlpha.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/addAlpha.R 3 | \name{addAlpha} 4 | \alias{addAlpha} 5 | \title{Color transparency} 6 | \usage{ 7 | addAlpha(col, alpha = 0.3) 8 | } 9 | \arguments{ 10 | \item{col}{Vector of color names (\code{\link{colors}}), hexadecimal or integer that can be interpreted by \code{\link{col2rgb}}} 11 | 12 | \item{alpha}{Level of semi-transparency. between 0 (transparent) and 1 (intransparent). Can also be a vector. DEFAULT: 0.3} 13 | } 14 | \value{ 15 | character vector with hexadecimal color codes. 16 | } 17 | \description{ 18 | Make existing colors semi-transparent (add alpha) 19 | } 20 | \examples{ 21 | 22 | addAlpha("red", c(0.1, 0.3, 0.6, 1)) 23 | addAlpha(1:3) 24 | addAlpha(1:3, 1:3/3) 25 | NewColors <- addAlpha(c("red","blue","yellow","green", "purple"), 0:200/200) 26 | plot(runif(1000), col=NewColors, pch=16, cex=2) 27 | 28 | # use addFade for line segments, because of overlapping dots 29 | set.seed(1); x <- cumsum(rnorm(30)) ; y <- x-2 30 | plot(x, type="n") 31 | segments(x0=1:29,y0=head(x,-1), x1=2:30,y1=x[-1], col=addAlpha(4, 29:0/30), lwd=10) 32 | segments(x0=1:29,y0=head(y,-1), x1=2:30,y1=y[-1], col=addFade (4, 29:0/30), lwd=10) 33 | 34 | } 35 | \seealso{ 36 | \code{\link{addFade}}, \code{\link{rgb}}, \code{\link{colors}}, \code{\link{col2rgb}} 37 | } 38 | \author{ 39 | Berry Boessenkool, \email{berry-b@gmx.de}, June 2014 Based on suggestion by Mathias Seibert, Dec. 2013 40 | } 41 | \keyword{color} 42 | \keyword{dplot} 43 | -------------------------------------------------------------------------------- /man/addFade.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/addFade.R 3 | \name{addFade} 4 | \alias{addFade} 5 | \title{Color fade out} 6 | \usage{ 7 | addFade(col, fade = 0.3, target = "white", ...) 8 | } 9 | \arguments{ 10 | \item{col}{Vector of color names (\code{\link{colors}}), hexadecimal or integer that can be interpreted by \code{\link{col2rgb}}} 11 | 12 | \item{fade}{Level of fading towards target. between 0 (target) and 1 (col). Can also be a vector. DEFAULT: 0.3} 13 | 14 | \item{target}{Target color that should be faded into. DEFAULT: "white"} 15 | 16 | \item{\dots}{Further arguments passed to \code{\link{colorRamp}}} 17 | } 18 | \value{ 19 | character matrix with hexadecimal color codes. 20 | } 21 | \description{ 22 | Make existing colors fade away to white 23 | } 24 | \examples{ 25 | 26 | plot(1:11, pch=16, cex=3, col=addFade(2, 10:0/10)) 27 | plot(1:11, pch=16, cex=3, col=addFade(2, 10:0/10, target="blue")) 28 | plot(1:11, pch=16, cex=3, col=addFade(2, 10:0/10, target=3:4)) 29 | plot(1:21, pch=16, cex=3, col=addFade(2:3, 10:0/10)) 30 | plot(1:21, pch=16, cex=3, col=addFade(2:3, 10:0/10, target=4:5)) 31 | NewColors <- addFade(c("red","blue","yellow","green", "purple"), 0:200/200) 32 | plot(runif(1000), col=NewColors, pch=16, cex=2) 33 | 34 | } 35 | \seealso{ 36 | \code{\link{addAlpha}}, \code{\link{colorRamp}}, \code{\link{colors}} 37 | } 38 | \author{ 39 | Berry Boessenkool, \email{berry-b@gmx.de}, Feb 2016 40 | } 41 | \keyword{color} 42 | \keyword{dplot} 43 | -------------------------------------------------------------------------------- /man/addRows.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/addRows.R 3 | \name{addRows} 4 | \alias{addRows} 5 | \title{Add n rows to a data.frame} 6 | \usage{ 7 | addRows(df, n, values = NA) 8 | } 9 | \arguments{ 10 | \item{df}{Dataframe object} 11 | 12 | \item{n}{Number of rows to add} 13 | 14 | \item{values}{Values to be used in the new rows. DEFAULT: NA} 15 | } 16 | \value{ 17 | A data.frame 18 | } 19 | \description{ 20 | simple Helper-Function to add n rows to a data.frame. 21 | } 22 | \examples{ 23 | 24 | MYDF <- data.frame(A=5:3, B=2:4) 25 | addRows(MYDF, 3) 26 | 27 | } 28 | \seealso{ 29 | \code{\link{insertRows}}, \code{\link{sortDF}}, 30 | \code{\link{data.frame}}, \code{\link{matrix}}, \code{\link{rbind}} 31 | } 32 | \author{ 33 | Berry Boessenkool, \email{berry-b@gmx.de}, Jan 2014 34 | } 35 | \keyword{misc} 36 | -------------------------------------------------------------------------------- /man/anhang.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/anhang.R 3 | \name{anhang} 4 | \alias{anhang} 5 | \title{open the Appendix of Rclick} 6 | \usage{ 7 | anhang() 8 | } 9 | \value{ 10 | None, opens pdf in default viewer using \code{\link{system2}} 11 | } 12 | \description{ 13 | Open the Appendix of my R handbook found online at 14 | \url{https://github.com/brry/rclick} 15 | } 16 | \examples{ 17 | # anhang() # excluded from cran check because of external browser opening policy 18 | 19 | } 20 | \seealso{ 21 | \code{\link{funSource}} 22 | } 23 | \author{ 24 | Berry Boessenkool, \email{berry-b@gmx.de}, Jul 2016 25 | } 26 | -------------------------------------------------------------------------------- /man/approx2.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/approx2.R 3 | \name{approx2} 4 | \alias{approx2} 5 | \title{Smart linear NA interpolation} 6 | \usage{ 7 | approx2(x, fill = NULL, n = length(x), quiet = FALSE, ...) 8 | } 9 | \arguments{ 10 | \item{x}{Vector with (numeric) values} 11 | 12 | \item{fill}{Function to fill NAs at the start or end of the vector. See Details. DEFAULT: NULL} 13 | 14 | \item{n}{Number of points to interpolate to} 15 | 16 | \item{quiet}{Logical: suppress warning for no non-NA values? DEFAULT: FALSE} 17 | 18 | \item{\dots}{Further arguments passed to \code{\link{approx}}} 19 | } 20 | \value{ 21 | Vector with NAs replaced with interpolation (not a list, as in \code{\link{approx}}!) 22 | } 23 | \description{ 24 | Smart interpolation: as \code{\link{approx}}, approx2 fills NAs in a vector with linear interpolation, 25 | but unlike \code{\link{approx}}, it can handle NAs at the ends of a vector 26 | (takes the first/last value available for those). Also, approx2 returns a vector only. 27 | } 28 | \details{ 29 | The function fill is used to fill missing values at the ends of the vector. 30 | It could be mean or median, for example, but must be a function that accepts \code{na.rm=TRUE} as an argument. 31 | The default (NULL) means to use the first (or last) observation available. 32 | } 33 | \examples{ 34 | 35 | approx2(c(NA,NA)) # yields a message 36 | approx2(c(NA,NA, 6, 4, 8, 9, 3, 2, 1)) # fills with first non-NA value 37 | approx2(c( 2,NA, 6, 4, 8, 9, 3, 2, 1)) # interpolates linearly 38 | approx2(c( 2, 4, 6, 4, 8, 9,NA, 2,NA)) # linear, then last non-NA at end 39 | 40 | approx2(c(NA,NA, 6, 4, 8, 9, 3, 2, 1)) 41 | approx2(c(NA,NA, 6, 4, 8, 9, 3, 2, 1), fill=median) # first median, then linear 42 | approx2(c(NA,NA, 6, 4, 8, 9, 3, 2, 1), fill=mean) 43 | 44 | approx2(c( 3, 4, 6, 4, 8, 9,NA, 2,NA)) 45 | approx2(c( 3, 4, 6, 4, 8, 9,NA, 2,NA), fill=median) 46 | approx2(c( 3, 4, 6, 4, 8, 9,NA, 2,NA), fill=mean) 47 | 48 | approx2(c(NA,NA, 6, 4, 8, 9, 3, 2, 1), n=17) 49 | approx2(c( 2,NA, 6, 4, 8, 9, 3, 2, 1), n=17) 50 | approx2(c( 2, 4, 6, 4, 8, 9,NA, 2,NA), n=17) 51 | 52 | } 53 | \seealso{ 54 | \code{\link{approx}}, zoo::na.locf, \code{\link{ciBand}} for usage example 55 | } 56 | \author{ 57 | Berry Boessenkool, \email{berry-b@gmx.de}, July 2015 58 | } 59 | \keyword{arith} 60 | \keyword{dplot} 61 | -------------------------------------------------------------------------------- /man/around.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/around.R 3 | \name{around} 4 | \alias{around} 5 | \title{View values around an index} 6 | \usage{ 7 | around(x, i, n1 = 2, n2 = n1, convert = is.logical(i)) 8 | } 9 | \arguments{ 10 | \item{x}{Data.frame} 11 | 12 | \item{i}{Index (logical or integers)} 13 | 14 | \item{n1}{Number of elements shown before each i. DEFAULT: 2} 15 | 16 | \item{n2}{Number of elements shown after each i. DEFAULT: n1} 17 | 18 | \item{convert}{Use \code{\link{which}} to get the row numbers? 19 | DEFAULT: TRUE if i is boolean} 20 | } 21 | \value{ 22 | Nothing, calls \code{\link{View}} 23 | } 24 | \description{ 25 | View index rows of a data.frame with n surrounding rows 26 | } 27 | \examples{ 28 | \dontrun{ ## View should not be used in examples 29 | myDF <- data.frame(A=1:30, B=cumsum(rnorm(30))) 30 | myDF[c(5,7,23,29),1] <- NA 31 | around(myDF, i=is.na(myDF$A)) 32 | around(myDF, i=c(11,19), n2=0) 33 | } 34 | 35 | } 36 | \seealso{ 37 | \code{\link{sortDF}}, \code{\link{View}} 38 | } 39 | \author{ 40 | Berry Boessenkool, \email{berry-b@gmx.de}, Nov 2016 41 | } 42 | -------------------------------------------------------------------------------- /man/berryFunctions-package.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/berryFunctions-package.R 3 | \docType{package} 4 | \name{berryFunctions-package} 5 | \alias{berryFunctions} 6 | \alias{berryFunctions-package} 7 | \title{Berry's functions} 8 | \description{ 9 | Draw horizontal histograms, color scattered points by 3rd dimension, enhance date- and log-axis plots, zoom in X11 graphics, trace errors and warnings, use the unit hydrograph in a linear storage cascade, convert lists to data.frames and arrays, fit multiple functions. 10 | } 11 | \note{ 12 | Collection of functions, mainly connected with graphics and hydrology.\cr 13 | - zoom in X11 graphics\cr 14 | - plot rainfall-runoff data and optimize parameters for the unit hydrograph in the linear storage cascade\cr 15 | - write text to plots on top of colored fields in label size (halo-effect)\cr 16 | - draw scatterplots colored by 3rd dimension (as in image, which only deals with grids)\cr 17 | - draw histograms horizontally\cr 18 | - advancedly label date axes and logarithmic axes\cr 19 | - fit multiple functions (power, reciprocal, exponential, logarithmic, polynomial, rational) by regression\cr 20 | - convert lists to data.frames\cr 21 | - and more... 22 | 23 | At some places you'll find \code{## not run} in the examples. These code 24 | blocks were excluded from checking while building, mainly because they are 25 | interactive and need mouseclicks, or because they open another device/file. 26 | Normally, you should be able to run them in an interactive session. If you 27 | do find non-executable code, please tell me!\cr 28 | Feel free to suggest packages in which these functions would fit well.\cr 29 | I strongly depend on - and therefore welcome - any feedback!\cr\cr 30 | } 31 | \examples{ 32 | 33 | # see vignette("berryFunctions") 34 | 35 | } 36 | \seealso{ 37 | Useful links: 38 | \itemize{ 39 | \item \url{https://github.com/brry/berryFunctions} 40 | \item Report bugs at \url{https://github.com/brry/berryFunctions} 41 | } 42 | 43 | } 44 | \author{ 45 | Berry Boessenkool, \email{berry-b@gmx.de}, 2011-2017 46 | } 47 | \keyword{documentation} 48 | \keyword{package} 49 | -------------------------------------------------------------------------------- /man/betaPlotComp.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/betaPlotComp.R 3 | \name{betaPlotComp} 4 | \alias{betaPlotComp} 5 | \title{Compare beta distributions} 6 | \usage{ 7 | betaPlotComp( 8 | shape1 = c(0.5, 1:4, 10, 20), 9 | shape2 = shape1, 10 | cumulative = FALSE, 11 | cex = 0.8, 12 | las = 1, 13 | main = "", 14 | ylim = lim0(4), 15 | mar = rep(0, 4), 16 | oma = c(2, 2, 4.5, 2), 17 | mgp = c(3, 0.7, 0), 18 | keeppar = FALSE, 19 | textargs = NULL, 20 | ... 21 | ) 22 | } 23 | \arguments{ 24 | \item{shape1}{Vector of alpha values as in \code{\link{dbeta}}. DEFAULT: c(0.5, 1:4, 10,20)} 25 | 26 | \item{shape2}{Beta values to be compared. DEFAULT: shape1} 27 | 28 | \item{cumulative}{Should the cumulative density distribution line be added? DEFAULT: FALSE} 29 | 30 | \item{cex}{Character EXpansion size. DEFAULT: 0.8} 31 | 32 | \item{las}{Label Axis Style passed to \code{\link{axis}}. DEFAULT: 1} 33 | 34 | \item{main}{Main as in \code{\link{plot}}. DEFAULT: ""} 35 | 36 | \item{ylim}{LIMit for the Y axis. DEFAULT: lim0(4)} 37 | 38 | \item{mar}{MARgins for plot passed to \code{\link{par}}. DEFAULT: rep(0,4)} 39 | 40 | \item{oma}{Outer MArgins for plot passed to \code{\link{par}}. DEFAULT: c(2,2,4.5,2)} 41 | 42 | \item{mgp}{MarGin Placement. DEFAULT: c(3,0.7,0)} 43 | 44 | \item{keeppar}{Should margin parameters be kept instead of being restored to previous value? DEFAULT: FALSE} 45 | 46 | \item{textargs}{List of arguments passed to \code{\link{textField}}. DEFAULT: NULL} 47 | 48 | \item{\dots}{Further arguments passed to \code{\link{betaPlot}} like lines, fill, etc.} 49 | } 50 | \value{ 51 | None. Used for plotting. 52 | } 53 | \description{ 54 | Visually understand the effect of the beta distribution parameters 55 | } 56 | \note{ 57 | Tries to find suitable subplot for axis labels. This works only for increasing parameter values. 58 | } 59 | \examples{ 60 | 61 | betaPlotComp() 62 | betaPlotComp(oma=c(2,2,2,2), ylim=lim0(5.5), textargs=list(y=NA)) 63 | betaPlotComp(shape1=c(3,10,34), shape2=c(7,9,24)) 64 | 65 | } 66 | \seealso{ 67 | \code{\link{betaPlot}} 68 | } 69 | \author{ 70 | Berry Boessenkool, \email{berry-b@gmx.de}, Dec 2015 71 | } 72 | \keyword{distribution} 73 | \keyword{hplot} 74 | -------------------------------------------------------------------------------- /man/between.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/between.R 3 | \name{between} 4 | \alias{between} 5 | \title{Are values between a and b?} 6 | \usage{ 7 | between(x, a, b = a, incl = TRUE, aincl = incl, bincl = incl, quiet = FALSE) 8 | } 9 | \arguments{ 10 | \item{x}{Numerical vector} 11 | 12 | \item{a, b}{Numerical values/vectors specifying the borders of the interval. 13 | \code{\link{min}} and \code{max} are used, so they can be a vector.} 14 | 15 | \item{incl}{Logical. Include values on the borders? For x == border, TRUE 16 | will be returned. Specify per left and right border separately 17 | with the arguments \code{aincl} and \code{bincl}. DEFAULT: TRUE} 18 | 19 | \item{aincl, bincl}{Logical. Include values on left and right border, respectively? 20 | DEFAULT: \code{incl}} 21 | 22 | \item{quiet}{Logical. Suppress warning if a>b? DEFAULT: FALSE} 23 | } 24 | \value{ 25 | Logical (boolean) vector with TRUE/FALSE values 26 | } 27 | \description{ 28 | Are values within a certain interval? 29 | Basically a wrapper for \code{ x >= a & x <= b } to save repeating long x names twice. 30 | } 31 | \examples{ 32 | between(1:10, 4, 8) 33 | between(1:10, 4:8) # range as vector 34 | between(1:10, 8, 4) # warns about interval 35 | 36 | data.frame( incl.T=between(1:10, 4, 8), 37 | incl.F=between(1:10, 4, 8, incl=FALSE), 38 | aincl.F=between(1:10, 4, 8, aincl=FALSE), 39 | bincl.F=between(1:10, 4, 8, bincl=FALSE) ) 40 | 41 | } 42 | \seealso{ 43 | \code{\link{findInterval}} 44 | } 45 | \author{ 46 | Berry Boessenkool, \email{berry-b@gmx.de}, Aug 2017 47 | } 48 | \keyword{logic} 49 | -------------------------------------------------------------------------------- /man/bmap.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bmap.R 3 | \name{bmap} 4 | \alias{bmap} 5 | \title{title} 6 | \usage{ 7 | bmap(x = 13.12, y = 52.37, zm = 14, prov = NULL, collapsebg = TRUE, ...) 8 | } 9 | \arguments{ 10 | \item{x, y, zm}{passed to \code{leaflet::\link[leaflet]{setView}}} 11 | 12 | \item{prov}{named vector of providers. DEFAULT: NULL (nice selection)} 13 | 14 | \item{collapsebg}{Collapse background (map) layer selection? DEFAULT: TRUE} 15 | 16 | \item{\dots}{Ignored for now} 17 | } 18 | \value{ 19 | ReturnValue 20 | } 21 | \description{ 22 | description 23 | } 24 | \examples{ 25 | if(requireNamespace("leaflet", quietly=TRUE) && 26 | requireNamespace("leaflet.extras", quietly=TRUE)) 27 | bmap() 28 | 29 | } 30 | \author{ 31 | Berry Boessenkool, \email{berry-b@gmx.de}, Dec 2022 32 | } 33 | -------------------------------------------------------------------------------- /man/bpairs.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bpairs.R 3 | \name{bpairs} 4 | \alias{bpairs} 5 | \title{customized pairs plot} 6 | \usage{ 7 | bpairs(df, main = NULL, pch = 16, col = addAlpha("blue"), ...) 8 | } 9 | \arguments{ 10 | \item{df}{Data.frame. Can contain NAs. Character columns are excluded.} 11 | 12 | \item{main}{Title for the overall graph. DEFAULT: NULL (from input)} 13 | 14 | \item{\dots}{Further arguments passed to \code{\link{pairs}}} 15 | } 16 | \value{ 17 | invisible NULL 18 | } 19 | \description{ 20 | pairs plot with cor in the lower panel (can handle NAs), 21 | nice hist on the diagonal, nice scatterplot in the upper panel. 22 | Based on the examples in pairs. 23 | } 24 | \examples{ 25 | bpairs(mtcars[,1:5]) 26 | mtcarsNAs <- mtcars[,1:5] 27 | mtcarsNAs[2,3] <- NA 28 | mtcarsNAs[2:8,4] <- NA 29 | bpairs(mtcarsNAs) 30 | bpairs(iris) 31 | 32 | } 33 | \seealso{ 34 | \code{graphics::\link[graphics]{pairs}} 35 | } 36 | \author{ 37 | Berry Boessenkool, \email{berry-b@gmx.de}, Feb 2025 38 | } 39 | \keyword{aplot} 40 | -------------------------------------------------------------------------------- /man/catPal.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/pal.R 3 | \name{catPal} 4 | \alias{catPal} 5 | \title{Categorical color palette} 6 | \usage{ 7 | catPal(n = 12, set = 1, alpha = 1) 8 | } 9 | \arguments{ 10 | \item{n}{Number of colors, max 12. DEFAULT: 12} 11 | 12 | \item{set}{Integer for which set to use. Currently, only 1 is implemented.} 13 | 14 | \item{alpha}{Transparency (0=transparent, 1=fully colored). DEFAULT: 1} 15 | } 16 | \value{ 17 | Character string vector with color names 18 | } 19 | \description{ 20 | Categorical color palette according to IwantHue as displayed on 21 | \url{https://rockcontent.com/blog/subtleties-of-color-different-types-of-data-require-different-color-schemes/} 22 | } 23 | \examples{ 24 | plot(rep(1,12), pch=16, cex=5, col=catPal(12), xaxt="n") 25 | showPal() 26 | plot(cumsum(rnorm(40)), type="l", col=catPal()[1], ylim=c(-10,10)) 27 | for(i in 2:6) lines(cumsum(rnorm(40)), col=catPal()[i]) 28 | } 29 | \seealso{ 30 | \code{\link{showPal}}, \code{\link{seqPal}}, \code{\link{divPal}} 31 | } 32 | \author{ 33 | Berry Boessenkool, \email{berry-b@gmx.de}, Apr 2019 34 | } 35 | \keyword{color} 36 | \keyword{dplot} 37 | -------------------------------------------------------------------------------- /man/checkFile.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/checkFile.R 3 | \name{checkFile} 4 | \alias{checkFile} 5 | \title{check file existence} 6 | \usage{ 7 | checkFile(file, warnonly = FALSE, trace = TRUE, pwd = TRUE, nprint = 2) 8 | } 9 | \arguments{ 10 | \item{file}{Filename(s) as character string to be checked for existence.} 11 | 12 | \item{warnonly}{Logical: Only issue a \code{\link{warning}} instead of an 13 | error with \code{\link{stop}}? DEFAULT: FALSE} 14 | 15 | \item{trace}{Logical: Add function call stack to the message? DEFAULT: TRUE} 16 | 17 | \item{pwd}{Logical: Print working directory in message? DEFAULT: TRUE} 18 | 19 | \item{nprint}{Integer: number of filenames to be printed. 20 | The rest is abbreviated with (and n others). DEFAULT: 2} 21 | } 22 | \value{ 23 | TRUE/FALSE, invisibly 24 | } 25 | \description{ 26 | check whether files exist and give a useful error/warning/message 27 | } 28 | \examples{ 29 | is.error( checkFile("FileThatDoesntExist.txt") ) 30 | checkFile("FileThatDoesntExist.txt", warnonly=TRUE) 31 | checkFile("FileThatDoesntExist.txt", warnonly=TRUE, trace=FALSE) 32 | 33 | checkFile("./", warnonly=TRUE) 34 | checkFile(c("./",".//"), warnonly=TRUE) 35 | 36 | \dontrun{## Excluded from CRAN checks because of file creation 37 | # Vectorized: 38 | file.create("DummyFile2.txt") 39 | checkFile("DummyFile2.txt/") 40 | checkFile(paste0("DummyFile",1:3,".txt"), warnonly=TRUE) 41 | is.error(checkFile(paste0("DummyFile",1:3,".txt") ), TRUE, TRUE) 42 | file.remove("DummyFile2.txt") 43 | 44 | is.error(compareFiles("dummy.nonexist", "dummy2.nonexist"), TRUE, TRUE) 45 | is.error(checkFile("dummy.nonexist"), TRUE, TRUE) 46 | } 47 | 48 | dingo <- function(k="brute.nonexist", trace=TRUE) 49 | checkFile(k, warnonly=TRUE, trace=trace) 50 | dingo() 51 | dingo("dummy.nonexist") 52 | 53 | upper <- function(h, ...) dingo(c(h, "dumbo.nonexist"), ...) 54 | upper("dumbo2.nonexist") 55 | upper(paste0("dumbo",2:8,".nonexist")) 56 | upper(paste0("dumbo",2:8,".nonexist"), trace=FALSE) 57 | 58 | 59 | } 60 | \seealso{ 61 | \code{\link{file.exists}} 62 | } 63 | \author{ 64 | Berry Boessenkool, \email{berry-b@gmx.de}, May 2016 65 | } 66 | \keyword{file} 67 | -------------------------------------------------------------------------------- /man/circle.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/circle.R 3 | \name{circle} 4 | \alias{circle} 5 | \title{Draw circle with a given radius} 6 | \usage{ 7 | circle(x, y, r, locnum = 100, ...) 8 | } 9 | \arguments{ 10 | \item{x}{x coordinate of points, numeric value of length 1} 11 | 12 | \item{y}{y coordinate} 13 | 14 | \item{r}{radius of the circle in units of current plot. 15 | Can have two values for an ellipse.} 16 | 17 | \item{locnum}{number of calculated points on the circle (more means smoother but slower). DEFAULT: 100} 18 | 19 | \item{\dots}{further arguments passed to \code{\link{polygon}}, like col, border, lwd} 20 | } 21 | \value{ 22 | data.frame of coordinates, invisible 23 | } 24 | \description{ 25 | Draws a filled circle with a certain radius (in existing plot's units) using \code{\link{polygon}} and \code{\link{sin}} 26 | } 27 | \note{ 28 | If circles look like ellipsis, use plot(... asp=1) 29 | } 30 | \examples{ 31 | 32 | plot(1:20, type="n", asp=1) 33 | circle(5,5, r=3) # 1:1 aspect shows they're really circles and not ellipses. 34 | circle(15,10, r=4, locnum=12, col=2, border=4, lwd=3) 35 | 36 | # can not be vectorized: 37 | x <- sample(1:20, 15) ; y <- sample(1:20, 15) ; r <- runif(20)*3 38 | circle(x,y,r, col=rgb(1,0.5,0,alpha=0.4), border=NA) 39 | for(i in 1:15) circle(x[i],y[i],r[i], col=rgb(1,0.5,0,alpha=0.4), border=NA) 40 | 41 | } 42 | \seealso{ 43 | \code{\link{symbols}}, \code{\link{polygon}} 44 | } 45 | \author{ 46 | Berry Boessenkool, \email{berry-b@gmx.de}, 2012 47 | } 48 | \keyword{aplot} 49 | -------------------------------------------------------------------------------- /man/compareDist.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/compareDist.R 3 | \name{compareDist} 4 | \alias{compareDist} 5 | \title{compare distributions} 6 | \usage{ 7 | compareDist( 8 | df, 9 | plot = 1:4, 10 | bw = "SJ", 11 | col = catPal(ncol(df), alpha = 0.3), 12 | main = paste("Distributions of", deparse(substitute(df))), 13 | xlab = "Values", 14 | ylab = "Density", 15 | legpos1 = "topleft", 16 | legpos2 = NULL, 17 | horizontal = FALSE, 18 | ... 19 | ) 20 | } 21 | \arguments{ 22 | \item{df}{Data.frame with (named) columns.} 23 | 24 | \item{plot}{Integers: which graphics to plot?\cr 25 | Plot 1: overlaid density estimates\cr 26 | Plot 2: multipanel histogram\cr 27 | Plot 3: boxplot\cr 28 | Plot 4: violin plot, if package \code{vioplot} is available.\cr 29 | DEFAULT: 1:4} 30 | 31 | \item{bw}{Bandwidth passed to \code{\link{density}} for plot 1. DEFAULT: "SJ"} 32 | 33 | \item{col}{Color (vector). DEFAULT: \code{\link{catPal}(ncol(df), alpha=0.3)}} 34 | 35 | \item{main}{Title. DEFAULT: "Distributions of [df name]"} 36 | 37 | \item{xlab, ylab}{Axis labels for plot 1. DEFAULT: xlab="Values", ylab="Density"} 38 | 39 | \item{legpos1, legpos2}{Legend position for plot 1. DEFAULT: "topleft", NULL} 40 | 41 | \item{horizontal}{Should boxplot and vioplot (plot 3 and 4) be horizontal? DEFAULT: FALSE} 42 | 43 | \item{\dots}{Further arguments passed to \code{\link{polygon}} (plot 1), 44 | \code{\link{groupHist}} (plot 2) 45 | \code{\link{boxplot}} (plot 3) and 46 | \code{vioplot::\link[vioplot]{vioplot}} (plot 4)} 47 | } 48 | \value{ 49 | df, invisible 50 | } 51 | \description{ 52 | compare multiple distributions. All based on columns in a data.frame. 53 | Creates several plots based on the integers present in \code{plot}. 54 | } 55 | \examples{ 56 | fakedata <- data.frame(norm=rnorm(30), exp=rexp(30), unif=runif(30)) 57 | compareDist(fakedata) 58 | 59 | } 60 | \seealso{ 61 | \code{\link{groupHist}} 62 | } 63 | \author{ 64 | Berry Boessenkool, \email{berry-b@gmx.de}, Aug 2020 65 | } 66 | \keyword{hplot} 67 | -------------------------------------------------------------------------------- /man/compareFiles.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/compareFiles.R 3 | \name{compareFiles} 4 | \alias{compareFiles} 5 | \title{Compare textfiles for equality} 6 | \usage{ 7 | compareFiles( 8 | file1, 9 | file2, 10 | nr = 20, 11 | startline = 1, 12 | endline = length(f1), 13 | quiet = FALSE, 14 | ... 15 | ) 16 | } 17 | \arguments{ 18 | \item{file1, file2}{Filenames to be read by \code{\link{readLines}}.} 19 | 20 | \item{nr}{number of results printed. DEFAULT: 20} 21 | 22 | \item{startline, endline}{start and end lines, e.g. to exclude section that is already compared.} 23 | 24 | \item{quiet}{show warnings about file lengths? DEFAULT: FALSE} 25 | 26 | \item{\dots}{further arguments passed to \code{\link{readLines}}} 27 | } 28 | \value{ 29 | Vector of line numbers that differ, result from \code{\link{head}(..., nr)} 30 | } 31 | \description{ 32 | Returns the line numbers where two (text)files differ 33 | } 34 | \examples{ 35 | 36 | filenames <- system.file(paste0("extdata/versuch",1:2,".txt"), package="berryFunctions") 37 | compareFiles(filenames[1], filenames[2], warn=FALSE) 38 | 39 | } 40 | \seealso{ 41 | \url{https://text-compare.com/} which I sadly only discovered after writing this function, 42 | \code{\link{dupes}} for finding duplicate lines, \code{\link{combineFiles}} 43 | } 44 | \author{ 45 | Berry Boessenkool, \email{berry-b@gmx.de}, Aug 2014 46 | } 47 | \keyword{IO} 48 | \keyword{character} 49 | \keyword{file} 50 | -------------------------------------------------------------------------------- /man/convertUmlaut.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/convertUmlaut.R 3 | \name{convertUmlaut} 4 | \alias{convertUmlaut} 5 | \title{Convert German Umlaute to ASCII} 6 | \usage{ 7 | convertUmlaut(x) 8 | } 9 | \arguments{ 10 | \item{x}{Character string(s) containing German Umlaute} 11 | } 12 | \value{ 13 | Character strings 14 | } 15 | \description{ 16 | Convert German Umlaute (ae, oe, ue, ss) to ASCII. 17 | Conversion happens case sensitive for the first three. 18 | } 19 | \examples{ 20 | \dontrun{ 21 | link <- paste0("ftp://ftp-cdc.dwd.de/pub/CDC/observations_germany/climate/", 22 | "monthly/kl/recent/KL_Monatswerte_Beschreibung_Stationen.txt") 23 | weatherstations <- read.fwf(link, widths=c(6,9,10,16,11,8,41,99), skip=3) 24 | examples <- trimws(weatherstations[c(153, 509, 587, 2, 651, 851),7]) 25 | examples 26 | convertUmlaut(examples) # note how lower and upper case is kept 27 | } 28 | 29 | } 30 | \seealso{ 31 | \code{tools::\link[tools]{showNonASCII}}, \code{\link{gsub}}, 32 | \code{\link{iconv}(x, to="ASCII//TRANSLIT")} 33 | } 34 | \author{ 35 | Berry Boessenkool, \email{berry-b@gmx.de}, Oct-Nov 2016 36 | } 37 | \keyword{character} 38 | -------------------------------------------------------------------------------- /man/count.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/count.R 3 | \name{count} 4 | \alias{count} 5 | \title{count string occurrences} 6 | \usage{ 7 | count(pattern, x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{charstring (vector)} 11 | 12 | \item{\dots}{Further arguments passed to \code{\link{gregexpr}}} 13 | 14 | \item{a}{character string (can have regex)} 15 | } 16 | \value{ 17 | single integer 18 | } 19 | \description{ 20 | count how often a certain string occurs, summing over a vector 21 | } 22 | \examples{ 23 | vec210 <- c("with abc + abc + ab", "also abcde", "no alphabet") 24 | vec021 <- c("no alphabet", "this has abcabc + ab", "also abcde") 25 | vec000 <- c("this has no", "alphabet", "at all") 26 | vec4 <- "this has abc and abcabcabc" 27 | stopifnot(count("abc", vec210) == 3) 28 | stopifnot(count("abc", vec021) == 3) 29 | stopifnot(count("abc", vec000) == 0) 30 | stopifnot(count("abc", vec4 ) == 4) 31 | 32 | } 33 | \author{ 34 | Berry Boessenkool, \email{berry-b@gmx.de}, Jan 2025 35 | } 36 | -------------------------------------------------------------------------------- /man/createFun.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/createFun.R 3 | \name{createFun} 4 | \alias{createFun} 5 | \title{create function framework} 6 | \usage{ 7 | createFun(fun, path = ".", open = TRUE) 8 | } 9 | \arguments{ 10 | \item{fun}{Character string or unquoted name. Function that will be created with identical filename.} 11 | 12 | \item{path}{Path to package in development (including package name itself). 13 | Is passed to \code{\link{packagePath}}. DEFAULT: "."} 14 | 15 | \item{open}{Logical: open the file? If several instances of Rstudio are open, 16 | the last one (not necessarily the active one) will be used. 17 | DEFAULT: TRUE} 18 | } 19 | \value{ 20 | file name as character string 21 | } 22 | \description{ 23 | create a file with a complete (Roxygen) framework for a new function in a package 24 | } 25 | \details{ 26 | Tries to open the file in the standard editor for .R files using \code{\link{system2}} 27 | } 28 | \examples{ 29 | #createFun("myNewFunction") 30 | } 31 | \seealso{ 32 | \code{\link{system2}}, \code{\link{funSource}}, Roxygen2: 33 | \url{https://cran.r-project.org/package=roxygen2/vignettes/rd.html} 34 | } 35 | \author{ 36 | Berry Boessenkool, \email{berry-b@gmx.de}, March 2016 37 | } 38 | \keyword{documentation} 39 | -------------------------------------------------------------------------------- /man/createPres.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/createPres.R 3 | \name{createPres} 4 | \alias{createPres} 5 | \title{Create .Rnw presentation template} 6 | \usage{ 7 | createPres( 8 | presname = "pres", 9 | dir = "presentation", 10 | path = ".", 11 | asp = 169, 12 | navbullets = FALSE, 13 | bgblack = FALSE, 14 | open = TRUE 15 | ) 16 | } 17 | \arguments{ 18 | \item{presname}{Name of .Rnw file to be created. DEFAULT: "pres"} 19 | 20 | \item{dir}{Name of directory that will contain .Rnw file and 21 | fig_extern folder. "_1" will be appended if already existing, 22 | see \code{\link{newFilename}}. DEFAULT: "presentation"} 23 | 24 | \item{path}{Location of \code{dir}. Passed to \code{\link{setwd}}. 25 | DEFAULT: "."} 26 | 27 | \item{asp}{Number to set as aspectratio. 43 for old 4:3 format. 28 | Possible values: 169, 1610, 149, 54, 43, 32. 29 | \bold{note}: if you set this, remember to change the default \code{fig.width}. 30 | DEFAULT: 169 (16:9 format)} 31 | 32 | \item{navbullets}{Logical: include navigation slide bullet points in header? 33 | This only takes effect when there are subsections. 34 | DEFAULT: FALSE} 35 | 36 | \item{bgblack}{Logical: set a black background instead of a white one? 37 | Requires all R graphics fg and bg colors to be changed! 38 | See "How to avoid death By PowerPoint" at 11:49 minutes 39 | \url{https://youtu.be/Iwpi1Lm6dFo?t=11m49s}. 40 | Change colors manually in the Rnw files searching for 41 | \code{bg=}, \code{linkcolor=}, \code{urlcolor=} 42 | in the preamble and \code{color} right after \code{begin document}. 43 | DEFAULT bgblack: FALSE} 44 | 45 | \item{open}{Logical: run \code{\link{openFile}}? DEFAULT: TRUE} 46 | } 47 | \description{ 48 | Create folder with .Rnw presentation template and fig_extern folder. 49 | } 50 | \examples{ 51 | \dontrun{ 52 | createPres("Berry_Conference") 53 | } 54 | 55 | } 56 | \seealso{ 57 | \code{\link{createFun}} 58 | } 59 | \author{ 60 | Berry Boessenkool, \email{berry-b@gmx.de}, Mar 2017 61 | } 62 | \keyword{file} 63 | -------------------------------------------------------------------------------- /man/dataStr.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/dataStr.R 3 | \name{dataStr} 4 | \alias{dataStr} 5 | \title{str of datasets} 6 | \usage{ 7 | dataStr( 8 | heads = FALSE, 9 | only = NULL, 10 | msg = heads, 11 | package = NULL, 12 | view = TRUE, 13 | ... 14 | ) 15 | } 16 | \arguments{ 17 | \item{heads}{Logical: display heads of all data.frames? 18 | If TRUE, \code{only} is ignored. DEFAULT: FALSE} 19 | 20 | \item{only}{Charstring class: give information only about objects of that class. 21 | Can also be TRUE to sort output by nrow/ncol 22 | DEFAULT: NULL (ignore)} 23 | 24 | \item{msg}{Logical: message str info? DEFAULT: FALSE} 25 | 26 | \item{package}{Package name. DEFAULT: NULL} 27 | 28 | \item{view}{Open dataframe with \code{\link{View}} (in Rstudio, if available)? DEFAULT: TRUE} 29 | 30 | \item{\dots}{Other arguments passed to \code{\link{data}}} 31 | } 32 | \value{ 33 | invisible data.frame. If \code{msg=TRUE}, prints via \code{\link{message}} in a for loop. 34 | } 35 | \description{ 36 | Print the \code{\link{str}} of each dataset returned by \code{\link{data}} 37 | } 38 | \examples{ 39 | 40 | \dontrun{ ## View should not be used in examples 41 | dataStr() # all loaded packages on search path (package=NULL) 42 | # dataStr(package="datasets") # only datasets in base R package datasets 43 | dataStr(only=TRUE) # sorted by nrow / ncol 44 | d <- dataStr(only="data.frame") # data.frames only 45 | sort(sapply(d$Object, function(dd) {sum(is.na(get(dd)))})) # datasets with NAs 46 | head(d) 47 | if(interactive()) View(d) # to sort in Rstudio Viewer 48 | d[,c("Object","ncol","nrow")] 49 | 50 | dataStr(heads=TRUE) # heads of all data.frames 51 | 52 | # dataStr(package="hms") # no datasets in package 53 | } 54 | 55 | } 56 | \seealso{ 57 | \code{\link{str}} 58 | } 59 | \author{ 60 | Berry Boessenkool, \email{berry-b@gmx.de}, November 2015, in search of good datasets for teaching 61 | } 62 | \keyword{documentation} 63 | \keyword{print} 64 | -------------------------------------------------------------------------------- /man/distance.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/distance.R 3 | \name{distance} 4 | \alias{distance} 5 | \title{Distance between points} 6 | \usage{ 7 | distance(x, y, xref, yref, along = FALSE) 8 | } 9 | \arguments{ 10 | \item{x}{vector with x-coordinate(s) of point(s)} 11 | 12 | \item{y}{ditto for y} 13 | 14 | \item{xref}{single x coordinate of reference point} 15 | 16 | \item{yref}{ditto for y} 17 | 18 | \item{along}{Logical: Should distances be computed along vector \code{(x,y)}? 19 | If TRUE, \code{(xref,yref)} are ignored. 20 | If both \code{(xref,yref)} are not given, along is set to TRUE.} 21 | } 22 | \value{ 23 | vector with the distances 24 | } 25 | \description{ 26 | Calculate distance between points on planar surface 27 | } 28 | \details{ 29 | The function is quite simple: \code{sqrt((xref - x)^2 + (yref - y)^2)} 30 | } 31 | \examples{ 32 | 33 | A <- c(3, 9,-1) 34 | B <- c(7, -2, 4) 35 | plot(A,B) 36 | text(A,B, paste0("P",1:3), adj=1.1) 37 | points(3,5, col=2, pch=16) 38 | segments(3,5, A,B) 39 | distance(A,B, 3,5) 40 | text(c(3.2,6,1), c(6,1,4), round(distance(A,B, 3,5),2) ) 41 | 42 | } 43 | \seealso{ 44 | \code{\link[spatstat.geom]{nndist}} in the package \code{spatstat.geom} 45 | for distance to nearest neighbour 46 | } 47 | \author{ 48 | Berry Boessenkool, \email{berry-b@gmx.de}, 2012 49 | } 50 | \keyword{spatial} 51 | -------------------------------------------------------------------------------- /man/divPal.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/pal.R 3 | \name{divPal} 4 | \alias{divPal} 5 | \title{Diverging color palette} 6 | \usage{ 7 | divPal( 8 | n = 100, 9 | reverse = FALSE, 10 | alpha = 1, 11 | rwb = FALSE, 12 | ryb = FALSE, 13 | gp = FALSE, 14 | br = FALSE, 15 | colors = NULL, 16 | ... 17 | ) 18 | } 19 | \arguments{ 20 | \item{n}{Number of colors. DEFAULT: 100} 21 | 22 | \item{reverse}{Reverse colors? DEFAULT: FALSE} 23 | 24 | \item{alpha}{Transparency (0=transparent, 1=fully colored). DEFAULT: 1} 25 | 26 | \item{rwb}{Should colors be in red-white-blue instead of brown-blue? DEFAULT: FALSE} 27 | 28 | \item{ryb}{Use red-yellow-blue instead of the default, with "khaki" in the center. DEFAULT: FALSE} 29 | 30 | \item{gp}{Use green-purple instead of the default. DEFAULT: FALSE} 31 | 32 | \item{br}{Use blue-red instead of the default. DEFAULT: FALSE} 33 | 34 | \item{colors}{If not NULL, a color vector used in \code{\link{colorRampPalette}}. DEFAULT: NULL} 35 | 36 | \item{\dots}{Further arguments passed to \code{\link{colorRamp}}} 37 | } 38 | \value{ 39 | Character string vector with color names 40 | } 41 | \description{ 42 | Diverging color palette: brown to blue, light colors in the middle, darker 43 | at the extremes, good for displaying values in two directions 44 | } 45 | \examples{ 46 | plot(rep(1,12), pch=16, cex=5, col=divPal(12), xaxt="n") 47 | showPal() 48 | } 49 | \references{ 50 | The default palette is originally in 12 shades in the IPCC Assessment Report 5 51 | Chapter 12 Fig 12.22, \url{https://www.ipcc.ch/report/ar5/wg1/}.\cr 52 | The green-purple and blue-red palettes are from NYtimes (originally with 8 shades), 53 | \url{https://www.nytimes.com/interactive/2017/03/21/climate/how-americans-think-about-climate-change-in-six-maps.html} 54 | } 55 | \seealso{ 56 | \code{\link{showPal}}, \code{\link{seqPal}}, \code{\link{catPal}}, \code{\link{addAlpha}}, 57 | \code{\link{colorRampPalette}}, package \code{RColorBrewer} 58 | } 59 | \author{ 60 | Berry Boessenkool, \email{berry-b@gmx.de}, Jan 2016 61 | } 62 | \keyword{color} 63 | \keyword{dplot} 64 | -------------------------------------------------------------------------------- /man/exp4p.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/exp4p.R 3 | \name{exp4p} 4 | \alias{exp4p} 5 | \title{4-parametric exponential function} 6 | \usage{ 7 | exp4p(x, y, digits = 2, plot = FALSE, las = 1, col = 1:6, legarg = NULL, ...) 8 | } 9 | \arguments{ 10 | \item{x, y}{x and y Data} 11 | 12 | \item{digits}{significant digits for rounding R^2. DEFAULT: 2} 13 | 14 | \item{plot}{plot data and fitted functions? DEFAULT: FALSE} 15 | 16 | \item{las}{label axis style, see \code{\link{par}}. DEFAULT: 1} 17 | 18 | \item{col}{6 colors for lines and legend texts. DEFAULT: 1:6} 19 | 20 | \item{legarg}{Arguments passed to \code{\link{legend}}. DEFAULT: NULL} 21 | 22 | \item{\dots}{further graphical parameters passed to \code{\link{plot}}} 23 | } 24 | \value{ 25 | Data.frame with the 4 parameters for each \code{\link{optim}} method 26 | } 27 | \description{ 28 | Fits an exponential function of the form a*e^(b*(x+c))+d 29 | } 30 | \details{ 31 | This is mainly a building block for mReg 32 | } 33 | \note{ 34 | Optim can be slow! It refers to the functions rmse and rsquare, also in this package. 35 | L-BFGS-B needs finite values. In case it doesn't get any 36 | with the initial parameters (as in the first example Dataset), 37 | it tries again with the parameters optimized via Nelder Mead. 38 | } 39 | \examples{ 40 | \dontrun{## Skip time consuming checks on CRAN 41 | # exponential decline of temperature of a mug of hot chocolate 42 | tfile <- system.file("extdata/Temp.txt", package="berryFunctions") 43 | temp <- read.table(tfile, header=TRUE, dec=",") 44 | head(temp) 45 | plot(temp) 46 | temp <- temp[-20,] # missing value - rmse would complain about it 47 | x <- temp$Minuten 48 | y <- temp$Temp 49 | rm(tfile, temp) 50 | 51 | exp4p(x,y, plot=TRUE) 52 | # y=49*e^(-0.031*(x - 0 )) + 25 correct, judged from the model: 53 | # Temp=T0 - Te *exp(k*t) + Te with T0=73.76, Tend=26.21, k=-0.031 54 | # optmethod="Nelder-Mead" # y=52*e^(-0.031*(x + 3.4)) + 26 wrong 55 | } 56 | 57 | } 58 | \seealso{ 59 | \code{\link{mReg}}, \code{\link{lm}} 60 | } 61 | \author{ 62 | Berry Boessenkool, \email{berry-b@gmx.de}, 2012-2013, outsourced from mReg in July 2014 63 | } 64 | \keyword{nonlinear} 65 | \keyword{regression} 66 | -------------------------------------------------------------------------------- /man/funSource.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/funSource.R 3 | \name{funSource} 4 | \alias{funSource} 5 | \title{Source code of a function} 6 | \usage{ 7 | funSource(x, character.only = is.character(x), local = FALSE) 8 | } 9 | \arguments{ 10 | \item{x}{Function name, with or without quotation marks. 11 | Trailing brackets are removed: \code{xx()} -> \code{"xx"}.\cr 12 | Can be \code{package::function}, which must be quoted for 13 | non-loaded packages.} 14 | 15 | \item{character.only}{If TRUE, look for \code{SomeFun} instead of \code{MyFun} 16 | in case \code{MyFun <- "SomeFun"}. 17 | DEFAULT: \code{\link{is.character}(x)}} 18 | 19 | \item{local}{Open offline version of the code? Lacks comments and 20 | original formatting of source code. DEFAULT: FALSE} 21 | } 22 | \value{ 23 | links that are also opened with \code{\link{browseURL}} 24 | } 25 | \description{ 26 | open source code of a function in a loaded or specified package on 27 | github.com/cran or github.com/wch/r-source 28 | } 29 | \examples{ 30 | \dontrun{ ## browser windows should not be opened in CRAN checks 31 | funSource("head") 32 | funSource(message()) # handles brackets if fun can be evaluated without input 33 | funSource("require", local=TRUE) # usefull when offline 34 | 35 | funSource("OSMscale::earthDist") # works even for non-installed CRAN packages 36 | 37 | is.error(funSource("earthDist"), TRUE, TRUE) # Error for unloaded package 38 | require(plotrix); require(scales) 39 | funSource(rescale) # from the last loaded package 40 | 41 | tail <- function(...) stop("This is a dummy function. Type: rm(tail)") 42 | funSource("tail") 43 | rm(tail) 44 | } 45 | 46 | } 47 | \seealso{ 48 | \url{https://github.com/brry/rskey#rskey} to add this as a keyboard shortcut 49 | } 50 | \author{ 51 | Berry Boessenkool, \email{berry-b@gmx.de}, Jan+Dec 2016, May 2017, April 2019 52 | } 53 | -------------------------------------------------------------------------------- /man/getName.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/getName.R 3 | \name{getName} 4 | \alias{getName} 5 | \title{get the name of an input in nested function calls} 6 | \usage{ 7 | getName(x) 8 | } 9 | \arguments{ 10 | \item{x}{input object name or character string} 11 | } 12 | \value{ 13 | Character string with the name 14 | } 15 | \description{ 16 | get the name of an input in nested function calls 17 | } 18 | \examples{ 19 | # This does not work well: 20 | 21 | lower <- function(x) deparse(substitute(x)) 22 | upper <- function(y) lower(y) 23 | lower(pi) # returns "pi", as expected 24 | upper(pi) # returns "y". 25 | 26 | # That's why there is getName: 27 | 28 | getName(pi) # returns "pi", as expected 29 | upper <- function(y) getName(y) 30 | upper(pi) # yay! 31 | 32 | upper("dummy") 33 | upper(dummy) # works also for nonexistent objects 34 | dummy <- 7 35 | upper("dummy") # still stable 36 | upper(dummy) # still stable 37 | 38 | upper(stackloss[1:5,]) 39 | 40 | upper2 <- function(data) upper(data) 41 | upper2("K") 42 | upper2(K) 43 | 44 | # getName only works correctly if x is not an evaluated object: 45 | lower2 <- function(inp, assign=FALSE) {if(assign) inp <- inp; getName(inp)} 46 | lower2(pi) # "pi" 47 | lower2(pi, TRUE) # "3.14159265358979" 48 | 49 | } 50 | \seealso{ 51 | \url{https://stackoverflow.com/a/26558733}, \code{\link{substitute}} 52 | } 53 | \author{ 54 | \url{https://stackoverflow.com/users/2725969/brodieg} 55 | Implementation Berry Boessenkool, \email{berry-b@gmx.de}, Sep 2016 56 | } 57 | \keyword{IO} 58 | \keyword{character} 59 | -------------------------------------------------------------------------------- /man/googleLink2pdf.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/googleLink2pdf.R 3 | \name{googleLink2pdf} 4 | \alias{googleLink2pdf} 5 | \title{extract pdf link from google search result} 6 | \usage{ 7 | googleLink2pdf(googlelink) 8 | } 9 | \arguments{ 10 | \item{googlelink}{Character string: A search result address} 11 | } 12 | \value{ 13 | Characterstring with only the basic link 14 | } 15 | \description{ 16 | restrict pdf link from a google search to actual link with text processing 17 | } 18 | \note{ 19 | The function is not vectorized! If you have many links, use a loop around this function... 20 | } 21 | \examples{ 22 | 23 | Link <- paste0("https://www.google.de/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1", 24 | "&cad=rja&sqi=2&ved=0CDIQFjAA&url=http\%3A\%2F\%2Fcran.r-project.org", 25 | "\%2Fdoc\%2Fmanuals\%2FR-intro.pdf&ei=Nyl4UfHeOIXCswa6pIC4CA", 26 | "&usg=AFQjCNGejDwPlor4togQZmQEQv72cK9z8A&bvm=bv.45580626,d.Yms") 27 | googleLink2pdf(Link) 28 | 29 | Link <- paste0("https://www.google.de/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1", 30 | "&cad=rja&uact=8&ved=0ahUKEwjLlfmClavRAhWaN1AKHcGSBjEQFgghMAA", 31 | "&url=http\%3A\%2F\%2Fstackoverflow.com\%2Fquestions\%2Ftagged\%2Fr", 32 | "&usg=AFQjCNHYj6HjSs6Lvczn9wMWxE3slCdq1Q&bvm=bv.142059868,d.ZWM") 33 | googleLink2pdf(Link) 34 | Link <- paste0("https://www.google.de/url?sa=t&rct=j&q=&esrc=s&source=web&cd=2", 35 | "&cad=rja&uact=8&ved=0ahUKEwjLlfmClavRAhWaN1AKHcGSBjEQFggpMAE&", 36 | "url=http\%3A\%2F\%2Fstackoverflow.com\%2Fquestions\%2Ftagged\%2F\%3Ftagnames", 37 | "\%3Dr\%26sort\%3Dactive&usg=AFQjCNGkPGHq05qwKLLW4vRXdmk2Olhmig&bvm=bv.142059868,d.ZWM") 38 | googleLink2pdf(Link) 39 | 40 | } 41 | \seealso{ 42 | \code{\link{strsplit}}, \code{\link{gsub}} 43 | } 44 | \author{ 45 | Berry Boessenkool, \email{berry-b@gmx.de}, 2012 46 | } 47 | \keyword{character} 48 | -------------------------------------------------------------------------------- /man/groupHist.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/groupHist.R 3 | \name{groupHist} 4 | \alias{groupHist} 5 | \title{Histogram for classes} 6 | \usage{ 7 | groupHist( 8 | df, 9 | x, 10 | g, 11 | xlab = "", 12 | ylab = "", 13 | breaks = 20, 14 | las = 1, 15 | main = NULL, 16 | unit = NA, 17 | col = "purple", 18 | ... 19 | ) 20 | } 21 | \arguments{ 22 | \item{df}{data.frame object name} 23 | 24 | \item{x}{column name of variable of interest} 25 | 26 | \item{g}{column name of groups (\code{INDEX in \link{tapply}, f in \link{split}})} 27 | 28 | \item{xlab, ylab}{axis labels. DEFAULT: ""} 29 | 30 | \item{breaks}{\code{\link{hist} breaks}. DEFAULT: 20} 31 | 32 | \item{las}{LabelAxisStyle, see \code{\link{par}}. DEFAULT: 1, means numbers on y-axis upright} 33 | 34 | \item{main}{Main title, internal default based on \code{d, x, unit} and \code{g}. DEFAULT: NULL} 35 | 36 | \item{unit}{Unit to be written into the default title. DEFAULT: NA} 37 | 38 | \item{col}{Color vector to be used, recycled.} 39 | 40 | \item{\dots}{further arguments passed to \code{\link{hist}}} 41 | } 42 | \value{ 43 | NULL, used for plotting 44 | } 45 | \description{ 46 | Improvement of \code{tapply(x, g, hist)} with x and g taken from a data.frame 47 | } 48 | \details{ 49 | Uses \code{\link{split}} to categorize into groups. 50 | } 51 | \examples{ 52 | 53 | groupHist(chickwts, weight, "feed", col="salmon") 54 | groupHist(chickwts, "weight", "feed", col=2, unit="grams at age 6 weeks") 55 | groupHist(chickwts, weight, feed, col="khaki", breaks=5, main="Hi there") 56 | groupHist(iris, Petal.Width, Species) 57 | 58 | } 59 | \seealso{ 60 | \code{\link{hist}}, \code{\link{tapply}} 61 | } 62 | \author{ 63 | Berry Boessenkool, \email{berry-b@gmx.de}, Jan 2015 64 | } 65 | \keyword{distribution} 66 | \keyword{dplot} 67 | \keyword{hplot} 68 | -------------------------------------------------------------------------------- /man/headtail.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/headtail.R 3 | \name{headtail} 4 | \alias{headtail} 5 | \title{head and tail} 6 | \usage{ 7 | headtail(x, n = 1, nh = n, nt = n, na = FALSE, ...) 8 | } 9 | \arguments{ 10 | \item{x}{Object} 11 | 12 | \item{n}{Number of elements/rows/lines at begin and end of object to be returned. DEFAULT: 1} 13 | 14 | \item{nh, nt}{Number for \code{\link{head}} and \code{\link{tail}}, respectively. DEFAULT: n} 15 | 16 | \item{na}{Add NA values in between to emphasize visibly that there is 17 | something inbetween the values? DEFAULT: FALSE} 18 | 19 | \item{\dots}{Further arguments passed to \code{\link{head}} and \code{\link{tail}}} 20 | } 21 | \value{ 22 | \code{\link{head}} result 23 | } 24 | \description{ 25 | show head and tail of an object with one command 26 | } 27 | \details{ 28 | Tries to find good methods of combining the two results according to \code{class(x)}. 29 | } 30 | \examples{ 31 | 32 | head(letters, n=3) 33 | headtail(letters) 34 | headtail(letters, n=3) 35 | headtail(letters, n=3, na=TRUE) 36 | 37 | head(letters, n=-10) 38 | headtail(letters, n=-10, na=TRUE) # doesn't make sense for headtail 39 | 40 | head(freeny.x, n=3) # matrix 41 | headtail(freeny.x, n=3, na=TRUE) # no names for head-part 42 | headtail(women, n=3, na=TRUE) # data.frame works fine 43 | 44 | head(freeny.y, n=3) 45 | headtail(freeny.y, n=3, na=TRUE) 46 | 47 | head(library, n=3) 48 | headtail(library, n=3, na=TRUE) 49 | headtail(library, na=TRUE) 50 | 51 | ftable(Titanic) 52 | head(stats::ftable(Titanic), n=4) 53 | headtail(stats::ftable(Titanic), n=4, na=TRUE) 54 | 55 | head(table(sample(1:9, 30, TRUE)), n=3) 56 | headtail(table(sample(1:9, 30, TRUE)), n=3, na=TRUE) 57 | 58 | head(table(state.division, state.region), n=3) 59 | headtail(table(state.division, state.region), n=3, na=TRUE) 60 | 61 | } 62 | \seealso{ 63 | \code{\link{head}} 64 | } 65 | \author{ 66 | Berry Boessenkool, \email{berry-b@gmx.de}, Mrz 2016 67 | } 68 | \keyword{manip} 69 | -------------------------------------------------------------------------------- /man/if.error.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/if.error.R 3 | \name{if.error} 4 | \alias{if.error} 5 | \title{expressions/values conditional on whether tested expression returns an error.} 6 | \usage{ 7 | if.error(expr, error_true, error_false) 8 | } 9 | \arguments{ 10 | \item{expr}{Expression to be tested for returning an error.} 11 | 12 | \item{error_true}{Value or expression to be executed if tested expression returns an error.} 13 | 14 | \item{error_false}{Value or expression to be executed if tested expression does not return an error.} 15 | } 16 | \value{ 17 | Returns value or expression stated in \code{error_true} or \code{error_false}, 18 | depending on whether the tested expression throws an error. 19 | } 20 | \description{ 21 | Does a given expression return an error? 22 | Return specific values/expressions for either case. 23 | Useful for loops when you want to easily control values based on errors that arise. 24 | } 25 | \examples{ 26 | if.error( log(3), "error", "no_error" ) 27 | if.error( log(3), "error", log(3) ) 28 | if.error( log(3), log(6), "no_error" ) 29 | if.error( log("a"), log(6), log(3) ) 30 | 31 | } 32 | \seealso{ 33 | \code{\link{is.error}} 34 | } 35 | \author{ 36 | Nick Bultman, \email{njbultman74@gmail.com}, September 2020 37 | } 38 | \keyword{error} 39 | \keyword{programming} 40 | -------------------------------------------------------------------------------- /man/is.error.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/is.error.R 3 | \name{is.error} 4 | \alias{is.error} 5 | \title{Check if an expression returns an error} 6 | \usage{ 7 | is.error(expr, tell = FALSE, force = FALSE) 8 | } 9 | \arguments{ 10 | \item{expr}{Expression to be tested for returning an error} 11 | 12 | \item{tell}{Logical: Should the error message be printed via \code{\link{message}}? DEFAULT: FALSE} 13 | 14 | \item{force}{Logical: Should an error be returned if the expression is not an error? DEFAULT: FALSE} 15 | } 16 | \value{ 17 | TRUE/FALSE 18 | } 19 | \description{ 20 | Does a given expression return an error? 21 | Useful for tests where you want to make sure your function throws an error. 22 | } 23 | \examples{ 24 | is.error( log(3) ) 25 | is.error( log("a") ) 26 | is.error( log(3), tell=TRUE ) 27 | is.error( log("a"), tell=TRUE ) 28 | stopifnot( is.error( log("a") ) ) # or shorter: 29 | is.error( log("a"), force=TRUE) 30 | # is.error( log(3), force=TRUE) 31 | stopifnot(is.error( is.error(log(3), force=TRUE) )) 32 | 33 | } 34 | \seealso{ 35 | \code{\link{stop}}, \code{\link{try}}, \code{\link{inherits}} 36 | } 37 | \author{ 38 | Berry Boessenkool, \email{berry-b@gmx.de}, May 2016 39 | } 40 | \keyword{error} 41 | \keyword{programming} 42 | -------------------------------------------------------------------------------- /man/learnVocab.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/learnVocab.R 3 | \name{learnVocab} 4 | \alias{learnVocab} 5 | \title{spaced learning} 6 | \usage{ 7 | learnVocab(vocfile = "C:/Dropbox/Sonstiges/Vokabeln.csv", nnew = 3) 8 | } 9 | \arguments{ 10 | \item{vocfile}{File with vocabulary (or whatever you want to learn). 11 | The first line must contain the learning day, see examples. 12 | The second line must contain LEVEL;known;new, the last two being 13 | (short) names, e.g. languages (known will be displayed first).} 14 | 15 | \item{nnew}{Number of new entries to be added interactively at the start. 16 | They can still be skipped by writing nothing and pressing the ENTER key. 17 | DEFAULT: 3} 18 | } 19 | \value{ 20 | Updated vocab list, invisibly. 21 | } 22 | \description{ 23 | spaced learning e.g. for vocabulary. Uses interactive questions.\cr 24 | Note: this currently clears the console!\cr 25 | Based on \url{https://ncase.me/remember/} by Nicky Case.\cr 26 | At the beginning, new vocab will be asked, skip with empty ENTER. 27 | } 28 | \examples{ 29 | \dontrun{ # Excluded from checks, works only interactively! 30 | # initiate empty vocab list: 31 | vocfile <- tempfile("myvocab",fileext=".csv") 32 | cat("learning_day 1\nLEVEL;DE;FR\n1;Das Haus;la maison\n", file=vocfile) 33 | 34 | learnVocab(vocfile) # asks new vocab, then tests and changes level as needed 35 | } 36 | 37 | } 38 | \author{ 39 | Berry Boessenkool, \email{berry-b@gmx.de}, Apr 2019 40 | } 41 | \keyword{file} 42 | -------------------------------------------------------------------------------- /man/legendmt.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/legendmt.R 3 | \name{legendmt} 4 | \alias{legendmt} 5 | \title{legend with multiline title} 6 | \usage{ 7 | legendmt( 8 | x, 9 | y = NULL, 10 | legend, 11 | title, 12 | x.intersp = 1, 13 | fill = NA, 14 | col = par("col"), 15 | border = NA, 16 | lty = NA, 17 | lwd = NA, 18 | pch = NA, 19 | ... 20 | ) 21 | } 22 | \arguments{ 23 | \item{x, y, legend}{Arguments as in \code{\link{legend}}} 24 | 25 | \item{title}{Character with linebreaks or vector of charstrings.} 26 | 27 | \item{x.intersp, fill, col, border, lty, lwd, pch}{Arguments as in \code{\link{legend}}} 28 | 29 | \item{\dots}{Further arguments passed to \code{\link{legend}}. 30 | If vectorized, please remember to prepend NAs or whatever.} 31 | } 32 | \value{ 33 | \code{\link{legend}} output 34 | } 35 | \description{ 36 | Draw a legend with title spanning several lines (i.e. with line breaks). 37 | Note that this is in development and not all inputs are correctly vectorized yet. 38 | } 39 | \examples{ 40 | plot(1:10) 41 | legend("topleft", letters[1:4], col=1:4, pch=1, title="very long title to be split up") 42 | legendmt("topleft", letters[1:4], col=1:4, pch=1, title="very long title\nnow splat up") 43 | 44 | # Alternative: 45 | plot(1:10) 46 | legend("topleft", "very long title to be split up") 47 | legend("topleft", letters[1:4], col=1:4, pch=1, inset=c(0,0.09) ) 48 | 49 | } 50 | \seealso{ 51 | \code{\link{legend}} 52 | } 53 | \author{ 54 | Berry Boessenkool, \email{berry-b@gmx.de}, Apr 2017 55 | } 56 | \keyword{aplot} 57 | -------------------------------------------------------------------------------- /man/library2.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/library2.R 3 | \name{library2} 4 | \alias{library2} 5 | \alias{require2} 6 | \title{install.package and library} 7 | \usage{ 8 | library2(name, quietly = FALSE, libargs = NULL, ...) 9 | } 10 | \arguments{ 11 | \item{name}{Name of the package(s). Can be quoted, must not.} 12 | 13 | \item{quietly}{passed to \code{\link{library}}. DEFAULT: FALSE} 14 | 15 | \item{libargs}{List of arguments passed to \code{\link{library}} like \code{lib.loc}, \code{verbose} etc. DEFAULT: NULL} 16 | 17 | \item{\dots}{Arguments passed to \code{\link{install.packages}} like \code{lib}, \code{repos} etc.} 18 | } 19 | \value{ 20 | \code{\link{message}s} help instruction. 21 | } 22 | \description{ 23 | install and load a package. If a package is not available, it is installed before being loaded 24 | } 25 | \note{ 26 | Passing a vector with packages will work, but give some warnings. 27 | } 28 | \examples{ 29 | 30 | \dontrun{ 31 | ## Excluded fom CRAN checks. Package installation on server is unnecessary. 32 | require2(ada) 33 | library2("statmod") 34 | } 35 | 36 | } 37 | \seealso{ 38 | \code{\link{install.packages}}, \code{\link{library}} 39 | } 40 | \author{ 41 | Berry Boessenkool, \email{berry-b@gmx.de}, 2014+2020 42 | } 43 | \keyword{package} 44 | -------------------------------------------------------------------------------- /man/lim0.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/lim0.R 3 | \name{lim0} 4 | \alias{lim0} 5 | \title{axis limits with one end at zero} 6 | \usage{ 7 | lim0(x, f = 1/27, curtail = TRUE) 8 | } 9 | \arguments{ 10 | \item{x}{Numeric. Vector with values} 11 | 12 | \item{f}{Numeric. Extension factor. DEFAULT: 0.04 as in extendrange used eg. by \code{\link{curve}}} 13 | 14 | \item{curtail}{Logical. Should the range returned be trimmed by 4\%? That way, 15 | plotting doesn't need the default \code{\link{par}} xaxs or yaxs changed. DEFAULT: TRUE} 16 | } 17 | \value{ 18 | Vector with two values: 0 and by 4% contra-extended max (as for xaxs="r") 19 | } 20 | \description{ 21 | Calculates the range needed for ylim or xlim in plot, so that axis 22 | starts at zero and is extended by 4\% at the other end 23 | } 24 | \examples{ 25 | 26 | # basic idea: 27 | val <- c(3.2, 1.8, 4.5, 2.8, 0.1, 2.9) # just some numbers 28 | plot(val, ylim=lim0(val) ) # you don't even have to set yaxs="i" ;-) 29 | 30 | # "normal" plot: 31 | plot(val) 32 | par("usr") # -0.076 4.676 33 | 34 | # if y-axis is not allowed to go below 0, and we're too lazy to set yaxs="i": 35 | plot(val, ylim=lim0(val) ) 36 | round( par("usr") , digits=5) # 0.00000 4.66296 37 | 38 | # with 0.04 extension as claimed by help page (1/27 in source code = 0.037): 39 | plot(val, ylim=lim0(val, f=0.04) ) 40 | round( par("usr") , digits=5) # zero is not included on axis anymore 41 | 42 | b <- -val 43 | plot(b) 44 | plot(b, ylim=lim0(b) ) # works with only negative values as well 45 | 46 | # can handle only-NA input: 47 | lim0(c(7,NA,NA,NA)[-1]) 48 | lim0(c(NA,NA,NA)) 49 | 50 | } 51 | \references{ 52 | \code{methods(plot)}, \code{\link[graphics]{plot.default}}. 53 | Actually, I found extendrange via \code{plot.function} in \code{curve} 54 | } 55 | \seealso{ 56 | The \code{\link{extendrange}()} utility in package \pkg{grDevices} 57 | } 58 | \author{ 59 | Berry Boessenkool, \email{berry-b@gmx.de}, 6.6.2013 60 | } 61 | \keyword{dplot} 62 | -------------------------------------------------------------------------------- /man/locArrow.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/locArrow.R 3 | \name{locArrow} 4 | \alias{locArrow} 5 | \title{arrow at locator point in graph} 6 | \usage{ 7 | locArrow(digits = 2, length = 0.1, code = 2, ...) 8 | } 9 | \arguments{ 10 | \item{digits}{Number of digits coordinates are rounded to with \code{\link{signif}}} 11 | 12 | \item{length}{Length of the edges of the arrow head (in inches). DEFAULT: 0.1} 13 | 14 | \item{code}{Direction of arrow head. DEFAULT: 2 (from first to last point clicked)} 15 | 16 | \item{\dots}{Further arguments passed to \code{\link{arrows}} like lwd, col etc} 17 | } 18 | \value{ 19 | Character string with code 20 | } 21 | \description{ 22 | Draw arrow at positions in a graph located by clicking and return the code to recreate it 23 | } 24 | \details{ 25 | Not tested across platforms yet... 26 | } 27 | \examples{ 28 | 29 | plot(cumsum(rnorm(60)), type="l") 30 | ## locArrow() # only do this manually in interactive() mode 31 | ## locArrow(col="blue", lwd=3) 32 | 33 | } 34 | \seealso{ 35 | \code{\link{locLine}}, \code{\link{locator}}, \code{\link{abline}} 36 | } 37 | \author{ 38 | Berry Boessenkool, \email{berry-b@gmx.de}, Jun 2016 39 | } 40 | \keyword{aplot} 41 | \keyword{iplot} 42 | -------------------------------------------------------------------------------- /man/locLine.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/locLine.R 3 | \name{locLine} 4 | \alias{locLine} 5 | \title{abline at locator point in graph} 6 | \usage{ 7 | locLine(h = TRUE, v = TRUE, n = 1, ...) 8 | } 9 | \arguments{ 10 | \item{h}{Draw horizontal line at clicked location? DEFAULT: TRUE} 11 | 12 | \item{v}{Draw vertical line at clicked location? DEFAULT: TRUE} 13 | 14 | \item{n}{Number of points to be clicked. DEFAULT: 1} 15 | 16 | \item{\dots}{Further arguments passed to \code{\link{abline}} like lty, lwd, col, etc} 17 | } 18 | \value{ 19 | \code{\link{locator}} result 20 | } 21 | \description{ 22 | Draw vertical and/or horizontal lines at positions in a graph located by clicking 23 | } 24 | \details{ 25 | Not tested across platforms yet... 26 | } 27 | \examples{ 28 | 29 | plot(cumsum(rnorm(60)), type="l") 30 | ## locLine() # only do this manually in interactive() mode 31 | } 32 | \seealso{ 33 | \code{\link{locArrow}}, \code{\link{locator}}, \code{\link{abline}} 34 | } 35 | \author{ 36 | Berry Boessenkool, \email{berry-b@gmx.de}, Mar 2016 37 | } 38 | \keyword{aplot} 39 | \keyword{iplot} 40 | -------------------------------------------------------------------------------- /man/locatorRS.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/locatorRS.R 3 | \name{locatorRS} 4 | \alias{locatorRS} 5 | \title{locator with immediate points in Rstudio} 6 | \usage{ 7 | locatorRS(n = 512, type = "p", ...) 8 | } 9 | \arguments{ 10 | \item{n}{Maximum number of points to plot.} 11 | 12 | \item{type}{As in \code{\link{locator}}, but passed to \code{\link{points}}. 13 | DEFAULT: "p"} 14 | 15 | \item{\dots}{Further arguments passed to \code{\link{points}}} 16 | } 17 | \value{ 18 | List with x and y 19 | } 20 | \description{ 21 | Have \code{\link{locator}} add points on the graph directly after clicking, even in Rstudio Graphics devices 22 | } 23 | \examples{ 24 | if(interactive()){ 25 | plot(1:10, type="n") 26 | locs <- locator(n=3, type="o") # click on locations in graph. 27 | # If you do not set n at beginning, press ESC to finish 28 | locs 29 | # In Rstudio, points only appear after finishing. 30 | locatorRS(7, col="blue", type="o") # plots after each click 31 | } 32 | 33 | } 34 | \seealso{ 35 | \url{https://stackoverflow.com/q/65147219/1587132} 36 | } 37 | \author{ 38 | Berry Boessenkool, \email{berry-b@gmx.de}, Dec 2020 39 | } 40 | \keyword{aplot} 41 | -------------------------------------------------------------------------------- /man/logHist.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/logHist.R 3 | \name{logHist} 4 | \alias{logHist} 5 | \title{Histogram of logarithmic values} 6 | \usage{ 7 | logHist( 8 | x, 9 | logargs = NULL, 10 | main = xmain, 11 | xlab = xname, 12 | col = "tan", 13 | add = FALSE, 14 | las = 1, 15 | ylim = NULL, 16 | freq = TRUE, 17 | quiet = FALSE, 18 | ... 19 | ) 20 | } 21 | \arguments{ 22 | \item{x}{Vector of numerical values} 23 | 24 | \item{logargs}{A list of arguments passed to \code{\link{logAxis}}. DEFAULT: NULL} 25 | 26 | \item{main}{Title of graph, internally from x. DEFAULT: internal name representation} 27 | 28 | \item{xlab}{X axis label. DEFAULT: internal: name of x} 29 | 30 | \item{col}{Color of histogram bars} 31 | 32 | \item{add}{Logical: add to existing plot?} 33 | 34 | \item{las}{Integer: label axis style. DEFAULT: 1 (numbers upright)} 35 | 36 | \item{ylim}{2 Numbers: y-axis range. DEFAULT: NULL} 37 | 38 | \item{freq}{Logical: counts instead of density? DEFAULT: TRUE} 39 | 40 | \item{quiet}{Logical: suppress warning about non-positive values? DEFAULT: FALSE} 41 | 42 | \item{\dots}{further arguments passed to \code{\link{hist}} 43 | like breaks, xlim=c(-1,3), ..., but not xaxt} 44 | } 45 | \value{ 46 | none 47 | } 48 | \description{ 49 | Draw histogram of values on a logarithmic scale with nice axis labels 50 | } 51 | \examples{ 52 | 53 | dat <- rbeta(1e4, 2, 18)*100 54 | hist(dat, col="tan", breaks=50) 55 | logHist(dat) 56 | logHist(dat, freq=FALSE) 57 | logHist(dat, breaks=50) 58 | logHist(dat,xlim=c(0,2)) # xlim in powers of ten 59 | logHist(c(-1,0,1,2,2,3,3,4,8,10,50)) # warning for negative values 60 | 61 | } 62 | \seealso{ 63 | \code{\link{logAxis}}, \code{\link{hist}} 64 | } 65 | \author{ 66 | Berry Boessenkool, \email{berry-b@gmx.de}, Feb 2016 67 | } 68 | \keyword{aplot} 69 | \keyword{dplot} 70 | -------------------------------------------------------------------------------- /man/logSpaced.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/logSpaced.R 3 | \name{logSpaced} 4 | \alias{logSpaced} 5 | \title{Logarithmically spaced points} 6 | \usage{ 7 | logSpaced( 8 | base = 1.1708, 9 | n = 20, 10 | min = 1, 11 | max = n, 12 | plot = TRUE, 13 | pch = 3, 14 | las = 1, 15 | ylab = "base", 16 | ... 17 | ) 18 | } 19 | \arguments{ 20 | \item{base}{Base for calculations, can be a vector to compare several bases. DEFAULT: 1.1708} 21 | 22 | \item{n}{Number of values to be calculated. DEFAULT: 30} 23 | 24 | \item{min, max}{Range where n values are to be distributed, single values each. DEFAULT: 1,n} 25 | 26 | \item{plot}{Should the points be plotted on a line? DEFAULT: TRUE} 27 | 28 | \item{pch, las}{PointCharacter and Label Axis Style. DEFAULT: 3,1} 29 | 30 | \item{ylab}{Y axis label. DEFAULT: "base"} 31 | 32 | \item{\dots}{Further arguments passed to \code{\link{plot}}} 33 | } 34 | \value{ 35 | Vector or matrix, depending on base input 36 | } 37 | \description{ 38 | Calculates values that are in logarithmic distance from each other 39 | e.g. to produce logarithmic interval borders.\cr 40 | For exact logarithmic spacing, use 41 | \code{10^\link{seq}(from=\link{log10}(1), to=\link{log10}(100), len=100)} 42 | } 43 | \note{ 44 | base >1 concentrates points at low values, base<1 at high values. 45 | \code{base} does not relate to \code{base} in \code{\link{log}}! 46 | } 47 | \examples{ 48 | 49 | logSpaced() 50 | logSpaced(base=c(1.1, 1.5, 2), n=6, min=5, max=10) 51 | d <- logSpaced(seq(0.8, 1.2, 0.025), main="logarithmically spaced points") 52 | 53 | # the default base for the default n (20) will give an approximately equal 54 | # bin width across the range on a logarithmic scale: 55 | d <- logSpaced() 56 | plot(d, rep(1,20), log="x") 57 | 58 | # For exactly spacing logarithmically, use 59 | plot(10^seq(from=log10(1), to=log10(100), len=100), log="y") 60 | 61 | } 62 | \seealso{ 63 | \code{\link{classify}}, \code{\link{log}}, 64 | \url{https://stackoverflow.com/a/29963530} 65 | } 66 | \author{ 67 | Berry Boessenkool, \email{berry-b@gmx.de}, Oct 2014 68 | } 69 | \keyword{arith} 70 | -------------------------------------------------------------------------------- /man/lsMem.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/lsMem.R 3 | \name{lsMem} 4 | \alias{lsMem} 5 | \title{Show memory size of objects in MB} 6 | \usage{ 7 | lsMem(n = 6, pos = 1, ...) 8 | } 9 | \arguments{ 10 | \item{n}{Number of Objects to be shown separately. The rest is combined into "sum rest". DEFAULT: 6} 11 | 12 | \item{pos}{Environment where \code{\link{ls}} looks for objects.} 13 | 14 | \item{\dots}{Further arguments passed to \code{\link{ls}}} 15 | } 16 | \value{ 17 | Named vector with object sizes in MB (MegaBytes) 18 | } 19 | \description{ 20 | Show memory size of the biggest objects in MB. Helps you find the biggest memory killers. 21 | } 22 | \examples{ 23 | 24 | \dontrun{ 25 | ## excluded from CRAN check - I forgot why, but there's probably a good reason 26 | lsMem() 27 | } 28 | 29 | } 30 | \references{ 31 | \url{https://stackoverflow.com/questions/1358003/tricks-to-manage-the-available-memory-in-an-r-session} 32 | } 33 | \seealso{ 34 | \code{\link{object.size}}, \code{\link{ls}} 35 | } 36 | \author{ 37 | Berry Boessenkool, \email{berry-b@gmx.de}, Feb 2014 38 | } 39 | \keyword{file} 40 | \keyword{programming} 41 | -------------------------------------------------------------------------------- /man/monthLabs.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/monthLabs.R 3 | \name{monthLabs} 4 | \alias{monthLabs} 5 | \title{Nicely spaced labels along a month} 6 | \usage{ 7 | monthLabs(startyear = 2002, stopyear = 2018, npm = 2, npy = NA) 8 | } 9 | \arguments{ 10 | \item{startyear}{Integer. starting year. DEFAULT: 2002} 11 | 12 | \item{stopyear}{Integer. ending year. DEFAULT: 2018} 13 | 14 | \item{npm}{Integer, one of 1,2,3,6 or 31. Number of labels per month. DEFAULT: 2\cr 15 | npm : days of the month\cr 16 | 1 : first day of each month within the given years\cr 17 | 2 : 1st and 15th day\cr 18 | 3 : 1, 10, 20\cr 19 | 6 : 1, 5, 10, 15, 20, 25. 20 | 31 : each day} 21 | 22 | \item{npy}{Integer, one of 1,2,3,4 or 6. Number of labels per year at equally spaced month-beginnings. 23 | If specified, npm is not considered at all. DEFAULT: NA} 24 | } 25 | \value{ 26 | Vector with Dates as returned by \code{\link{as.Date}}. 27 | } 28 | \description{ 29 | Create dates of certain days of the month for labeling 30 | } 31 | \note{ 32 | Spacing of days is not equal, but set to certain days of the month! 33 | This was originally developed for time series movie frames 34 | } 35 | \examples{ 36 | 37 | monthLabs(2014,2014, 3) # 3 days per month 38 | monthLabs(2013,2014, npy=3) # 3 months per year, equally spaced 39 | monthLabs(2014,2014, npy=4) # 4 months per year 40 | 41 | # see monthAxis for automatic plot labeling 42 | 43 | } 44 | \seealso{ 45 | \code{\link{timeAxis}} for nice labeling, 46 | \code{\link{timeAxis}} for automatic determination of npm/npy, 47 | \code{\link{as.Date}}, \code{\link{paste}} 48 | } 49 | \author{ 50 | Berry Boessenkool, \email{berry-b@gmx.de}, early 2013 51 | } 52 | \keyword{chron} 53 | -------------------------------------------------------------------------------- /man/movAvLines.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/movAvLines.R 3 | \name{movAvLines} 4 | \alias{movAvLines} 5 | \title{Moving average with different window widths} 6 | \usage{ 7 | movAvLines( 8 | x = 1:length(y), 9 | y, 10 | widths = c(3, 5, 7, 9, 11, 13), 11 | weights, 12 | col = "blue", 13 | alpha = 0.3, 14 | add = TRUE, 15 | las = 1, 16 | ... 17 | ) 18 | } 19 | \arguments{ 20 | \item{x}{x values of data. DEFAULT: 1:length(y)} 21 | 22 | \item{y}{y values that are smoothed with several window widths} 23 | 24 | \item{widths}{widths of \code{\link{movAv}} windows. DEFAULT: 2:7*2-1} 25 | 26 | \item{weights}{weights within each window} 27 | 28 | \item{col}{color passed to \code{\link{addAlpha}}. DEFAULT: "blue"} 29 | 30 | \item{alpha}{transparency passed to \code{\link{addAlpha}}. DEFAULT: 0.3} 31 | 32 | \item{add}{Logical: Add to existing plot?Set to FALSE to first create 33 | the scatterplot. DEFAULT: TRUE} 34 | 35 | \item{las}{LabelAxisStyle (only relevant if add=FALSE). DEFAULT: 1} 36 | 37 | \item{\dots}{further arguments passed to \code{\link{lines}}} 38 | } 39 | \description{ 40 | Add moving average lines with different window widths to a plot 41 | } 42 | \examples{ 43 | 44 | set.seed(42) 45 | movAvLines(y=cumsum(rnorm(50)), add=FALSE, lwd=3) 46 | 47 | } 48 | \seealso{ 49 | \code{\link{movAv}}, \code{\link{addAlpha}} 50 | } 51 | \author{ 52 | Berry Boessenkool, \email{berry-b@gmx.de}, May 2015 53 | } 54 | \keyword{manip} 55 | \keyword{smooth} 56 | \keyword{ts} 57 | -------------------------------------------------------------------------------- /man/na9.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/na9.R 3 | \name{na9} 4 | \alias{na9} 5 | \title{Prepend spaces before na.strings} 6 | \usage{ 7 | na9( 8 | nspace = 5, 9 | base = c(-9999, -999, -9.99, -9.999), 10 | sep = c(",", "."), 11 | digits = 0:4, 12 | more = NULL, 13 | ... 14 | ) 15 | } 16 | \arguments{ 17 | \item{nspace}{number of spaces prepended. DEFAULT: 5} 18 | 19 | \item{base}{Numeric: basic na.string numbers} 20 | 21 | \item{sep}{Separator string (comma or decimal point or both). DEFAULT: c(",",".")} 22 | 23 | \item{digits}{Number(s) of zeros to be appended. DEFAULT: 0:4} 24 | 25 | \item{more}{More structures added to base, like "NA", "--". digits and sep is not added to this! DEFAULT: NULL} 26 | 27 | \item{\dots}{Arguments passed to nothing currently} 28 | } 29 | \value{ 30 | Character strings 31 | } 32 | \description{ 33 | Returns a number of useful character strings with varying amount of spaces prepended. 34 | It can be used as \code{na.strings=na9()} in \code{\link{read.table}}. 35 | } 36 | \examples{ 37 | 38 | na9() 39 | na9(nspace=0, sep=".") 40 | na9(nspace=0, sep=".", more=c(NA,"-")) 41 | 42 | } 43 | \seealso{ 44 | \code{\link{paste}} 45 | } 46 | \author{ 47 | Berry Boessenkool, \email{berry-b@gmx.de}, Jan 2016 48 | } 49 | \keyword{IO} 50 | \keyword{file} 51 | -------------------------------------------------------------------------------- /man/newFilename.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/newFilename.R 3 | \name{newFilename} 4 | \alias{newFilename} 5 | \title{Create new filename if file already exists} 6 | \usage{ 7 | newFilename( 8 | filename, 9 | ignore = FALSE, 10 | overwrite = FALSE, 11 | tellignore = TRUE, 12 | pre = "", 13 | mid = "\\n", 14 | end = "", 15 | quiet = FALSE, 16 | ntrunc = 3 17 | ) 18 | } 19 | \arguments{ 20 | \item{filename}{Char (vector): file name(s).} 21 | 22 | \item{ignore}{Logical (vector, recycled): Ignore file? DEFAULT: FALSE} 23 | 24 | \item{overwrite}{Logical (vector, recycled): overwrite file? DEFAULT: FALSE} 25 | 26 | \item{tellignore}{Logical: Message about ignored files? DEFAULT: TRUE} 27 | 28 | \item{pre, mid, end}{Char: strings to append after traceback / message / filenames. 29 | DEFAULT: "", "\\n ", ""} 30 | 31 | \item{quiet}{Logical: Suppress messages about creating file(s)? DEFAULT: FALSE} 32 | 33 | \item{ntrunc}{Integer: Number of filenames printed in messages before they 34 | get truncated with message "(and xx more)". DEFAULT: 3} 35 | } 36 | \value{ 37 | newFilename returns the input with an added "_n" in the filename 38 | for each file that already existed. 39 | } 40 | \description{ 41 | Check if files already exist and append \code{_1} or \code{_2}, etc to the filename if needed, 42 | thereby giving useful messages. 43 | } 44 | \examples{ 45 | 46 | fns <- c("dummy1", "dummy2.txt", "berryFunctions.Rproj", 47 | "README.md", "dummy2.dummy", "DESCRIPTION", "dummy4.R", "dummy5") 48 | newFilename(fns) 49 | newFilename(fns, ignore=TRUE) 50 | newFilename(fns, ignore=rep(c(TRUE,FALSE), each=4) ) 51 | newFilename(fns, ignore=rep(c(TRUE,FALSE), each=4), tellignore=FALSE) 52 | newFilename(fns, ntrunc=2) 53 | newFilename(fns, overwrite=TRUE, ign=c(TRUE,TRUE,rep(FALSE,6))) 54 | newFilename("README.md") 55 | newFilename("dummy", mid=" ") # no line break 56 | 57 | } 58 | \seealso{ 59 | \code{\link{file.exists}} 60 | } 61 | \author{ 62 | Berry Boessenkool, \email{berry-b@gmx.de}, Oct 2016 + Jan 2017 63 | } 64 | \keyword{file} 65 | -------------------------------------------------------------------------------- /man/normTest.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/normTest.R 3 | \name{normTest} 4 | \alias{normTest} 5 | \title{Test values for normality of distribution} 6 | \usage{ 7 | normTest( 8 | v, 9 | plot = TRUE, 10 | main = deparse(substitute(v)), 11 | breaks = 15, 12 | col = "tan", 13 | legend = TRUE, 14 | ... 15 | ) 16 | } 17 | \arguments{ 18 | \item{v}{Vector of values to be tested for normality} 19 | 20 | \item{plot}{Plot the histogram with the corresponding 21 | normal density distribution? DEFAULT: TRUE} 22 | 23 | \item{main}{Graph title. DEFAULT: \code{deparse(substitute(v))}} 24 | 25 | \item{breaks}{Number of bins. Exact, unlike in \code{\link{hist}}. 26 | DEFAULT: 15} 27 | 28 | \item{col}{Color of bars. DEFAULT: "tan"} 29 | 30 | \item{legend}{Add legend text in topright? DEFAULT: TRUE} 31 | 32 | \item{\dots}{Further arguments passed to \code{\link{hist}}} 33 | } 34 | \value{ 35 | named vector of p values 36 | } 37 | \description{ 38 | Normality test: histogram with corresponding normal density distribution line, 39 | as well as p values for various normality tests.\cr 40 | The package \code{nortest} is needed for full functionality. 41 | } 42 | \examples{ 43 | normTest(rnorm(1000, mean=97, sd=8.9)) 44 | # if p > 0.05: accept Nullhypothesis that data are normally distributed. 45 | normTest(rexp(30)) 46 | 47 | if(requireNamespace("pbapply")) replicate <- pbapply::pbreplicate 48 | par(mfcol=c(7,6), mar=c(0,0.1,1,0.1), oma=c(2.5,1.5,2.5,0), las=1) 49 | invisible(sapply(c("rnorm(10)", "rnorm(100)", 50 | "rexp(10)", "rexp(100)", 51 | "runif(10)", "runif(100)"), function(vv){ 52 | check <- replicate(1e2, normTest(v=eval(str2lang(vv)), plot=FALSE)) 53 | for(n in rownames(check)) 54 | {hist(check[n,], breaks=seq(0,1,len=20), axes=FALSE, ylab="", xlab="", main="") 55 | if(n=="ShapiroWilk") title(main=vv, line=1, xpd=NA) 56 | if(vv=="rnorm(10)") title(ylab=n, line=0, xpd=NA) 57 | abline(v=0.05, col="blue", lwd=1, xpd=TRUE) 58 | } 59 | axis(1, at=0:1) 60 | })) 61 | title(main="P values of tests for normality with", outer=TRUE, line=1.5) 62 | 63 | } 64 | \seealso{ 65 | \code{\link{ks.test}}, \code{\link{shapiro.test}} 66 | } 67 | \author{ 68 | Berry Boessenkool, \email{berry-b@gmx.de}, Sep 2021 69 | } 70 | \keyword{distribution} 71 | -------------------------------------------------------------------------------- /man/normalizePathCP.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/normalizePathCP.R 3 | \name{normalizePathCP} 4 | \alias{normalizePathCP} 5 | \title{normalizePath Cross Platform} 6 | \usage{ 7 | normalizePathCP(path, winslash = "/", mustWork = FALSE) 8 | } 9 | \arguments{ 10 | \item{path}{Character vector of file paths} 11 | 12 | \item{winslash}{Path separator on Windows. 13 | DEFAULT: "/" (unlike \code{\link{normalizePath}})} 14 | 15 | \item{mustWork}{Logical for \code{\link{normalizePath}}. DEFAULT: FALSE} 16 | } 17 | \value{ 18 | path character string(s) 19 | } 20 | \description{ 21 | \code{\link{normalizePath}} Cross Platform: Returns absolute 22 | path even for not (yet) existing files even on Linux. 23 | On Windows, this is the default behaviour. 24 | } 25 | \examples{ 26 | 27 | normalizePath ("doesnotexist.file", mustWork=FALSE) # on unix not full path 28 | normalizePathCP("doesnotexist.file") # full path on all platforms 29 | 30 | normalizePath ("../doesnotexist.file", mustWork=FALSE) 31 | normalizePathCP("../doesnotexist.file") 32 | 33 | checknp <- function(a,b=a,d=getwd()) 34 | { 35 | aa <- normalizePathCP(a) 36 | bb <- if(d=="") b else paste0(d,"/",b) 37 | if(aa != bb) stop("'", a, "' -> '", aa, "', should be '",bb, "'.") 38 | aa 39 | } 40 | 41 | checknp("notexist.file") 42 | checknp("../notexist.file", "notexist.file", dirname(getwd())) 43 | checknp("notexistfolder/notexist.file") 44 | #checknp("/home/berry/notexist.file", d="") # fails on windows 45 | #checknp("S:/Dropbox/notexist.file",d="") # fails on linux 46 | 47 | } 48 | \seealso{ 49 | \code{\link{normalizePath}}, \code{\link{newFilename}} 50 | } 51 | \author{ 52 | Berry Boessenkool, \email{berry-b@gmx.de}, Nov 2017 53 | } 54 | \keyword{file} 55 | -------------------------------------------------------------------------------- /man/openFile.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/openFile.R 3 | \name{openFile} 4 | \alias{openFile} 5 | \title{open file in default application} 6 | \usage{ 7 | openFile(file, ...) 8 | } 9 | \arguments{ 10 | \item{file}{Filename to be opened, as character string.} 11 | 12 | \item{\dots}{Further arguments passed to \code{\link{system2}}} 13 | } 14 | \value{ 15 | Result of try(system2, ...), invisibly 16 | } 17 | \description{ 18 | open a file using \code{\link{system2}} with command based on operating system. 19 | Tries to open the file with the program associated with its file extension.\cr 20 | See \code{\link{openPDF}} to open files with sumatraPDF. 21 | } 22 | \examples{ 23 | \dontrun{ # excluded from CRAN checks, file opening not wanted 24 | openFile("README.md") 25 | openFile("Tests.R") 26 | openFile(c("README.md","Tests.R")) 27 | is.error(openFile("dummydummydoesntexist.R"), TRUE, TRUE) 28 | openFile(tempdir()) 29 | } 30 | #' # To open folders (not files) with system2: 31 | # "nautilus" on linux ubuntu 32 | # "open" or "dolphin" on mac 33 | # "explorer" or "start" on windows 34 | # But open / xdg-open seems to work as well 35 | 36 | } 37 | \references{ 38 | \url{https://askubuntu.com/questions/15354}, 39 | \url{https://apple.stackexchange.com/questions/212583} 40 | } 41 | \seealso{ 42 | \code{\link{openPDF}}, \code{\link{system2}}, \code{\link{checkFile}} 43 | } 44 | \author{ 45 | Berry Boessenkool, \email{berry-b@gmx.de}, Aug 2017 46 | } 47 | \keyword{file} 48 | -------------------------------------------------------------------------------- /man/openPDF.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/openPDF.R 3 | \name{openPDF} 4 | \alias{openPDF} 5 | \title{open PDF file with sumatra viewer} 6 | \usage{ 7 | openPDF( 8 | file, 9 | rspath = sub("rstudio.exe$", "", Sys.getenv("RSTUDIO_DESKTOP_EXE")), 10 | sumexe = NULL, 11 | ... 12 | ) 13 | } 14 | \arguments{ 15 | \item{file}{Filename to be opened, as character string. 16 | Files not ending in ".pdf" are ignored with a warning.} 17 | 18 | \item{rspath}{The path to Rstudio files. 19 | DEFAULT: \code{sub("rstudio.exe$", "", \link{Sys.getenv}("RSTUDIO_DESKTOP_EXE"))}} 20 | 21 | \item{sumexe}{The path to SumatraPDF.exe. DEFAULT: Null: added to \code{rspath}, e.g. 22 | "C:/Program Files/RStudio/resources/app/bin/sumatra/SumatraPDF.exe"} 23 | 24 | \item{\dots}{Further arguments passed to \code{\link{system}}} 25 | } 26 | \value{ 27 | Result of try(system, ...), invisibly 28 | } 29 | \description{ 30 | open PDF file with SumatraPDF viewer, which does not lock files against being edited. 31 | It is only available on windows, but comes bundled with Rstudio. 32 | If the executable is not found, \code{\link{openFile}} is called instead.\cr 33 | I suggest to first change some settings with \code{\link{sumatraInitialize}()}. 34 | } 35 | \examples{ 36 | # only desired in an interactive session, not on CRAN checks 37 | # openPDF( system.file("extdata/Anhang.pdf", package="berryFunctions") ) 38 | # openPDF( system.file(c("extdata/Anhang.pdf", "extdata/RainfallStationsMap.pdf"), 39 | # package="berryFunctions") ) 40 | 41 | } 42 | \seealso{ 43 | \code{\link{openFile}} for the default opening programm\cr 44 | \code{\link{sumatraInitialize}} for nice Sumatra default settings\cr 45 | \code{\link{pdfpng}} to create PDFs and PNGs simultaneously. 46 | } 47 | \author{ 48 | Berry Boessenkool, \email{berry-b@gmx.de}, May 2020 49 | } 50 | \keyword{file} 51 | -------------------------------------------------------------------------------- /man/packagePath.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/packagePath.R 3 | \name{packagePath} 4 | \alias{packagePath} 5 | \title{Base path of package} 6 | \usage{ 7 | packagePath(path = ".", file = NULL, warnonly = FALSE) 8 | } 9 | \arguments{ 10 | \item{path}{Path to (or below) package directory. DEFAULT: "."} 11 | 12 | \item{file}{Optional file name to be added to path. DEFAULT: NA} 13 | 14 | \item{warnonly}{Logical: if no part of the path is a package, give a warning 15 | and return the original input instead of stopping with an error. 16 | DEFAULT: FALSE} 17 | } 18 | \value{ 19 | Path character string 20 | } 21 | \description{ 22 | Base path of package (with DESCRIPTION file), per default at current getwd. 23 | Derived from devtools::package_file 24 | } 25 | \examples{ 26 | # packagePath() # may fail on cran checks 27 | 28 | } 29 | \seealso{ 30 | \code{\link{getwd}} 31 | } 32 | \author{ 33 | Berry Boessenkool, \email{berry-b@gmx.de}, Sep 2017 34 | } 35 | \keyword{file} 36 | -------------------------------------------------------------------------------- /man/parallelCode.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/parallelCode.R 3 | \name{parallelCode} 4 | \alias{parallelCode} 5 | \title{code chunk for parallelization} 6 | \usage{ 7 | parallelCode() 8 | } 9 | \description{ 10 | message a code chunk template for parallelization with progress bar on windows. 11 | On Linux, just use \code{pblapply(X, cl=8, FUN=fun)} 12 | } 13 | \examples{ 14 | parallelCode() 15 | 16 | } 17 | \seealso{ 18 | \code{\link{par_sapply}} 19 | } 20 | \author{ 21 | Berry Boessenkool, \email{berry-b@gmx.de}, Aug 2017 22 | } 23 | -------------------------------------------------------------------------------- /man/popleaf.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/popleaf.R 3 | \name{popleaf} 4 | \alias{popleaf} 5 | \title{create leaflet popup box info} 6 | \usage{ 7 | popleaf( 8 | df, 9 | sel = colnames(df), 10 | truncate = NULL, 11 | tstring = "[...]", 12 | exclude_geometry = TRUE, 13 | na.rm = FALSE 14 | ) 15 | } 16 | \arguments{ 17 | \item{df}{Data.frame} 18 | 19 | \item{sel}{Columns to be selected (Names or index or TRUE/FALSE vector). 20 | DEFAULT: colnames(df)} 21 | 22 | \item{truncate}{Numeric: number of characters beyond which to truncate columns. 23 | DEFAULT: NULL (no truncation)} 24 | 25 | \item{tstring}{Charstring to add at the end if truncated. DEFAULT: "[...]"} 26 | 27 | \item{exclude_geometry}{Remove column with the name "geometry" 28 | (as in sf objects) from the display? DEFAULT: TRUE} 29 | 30 | \item{na.rm}{Exclude NA entries from the display? DEFAULT: FALSE} 31 | } 32 | \value{ 33 | Vector with character strings 34 | } 35 | \description{ 36 | combine data.frame columns into a leaflet popup-box compatible format 37 | } 38 | \examples{ 39 | dat <- data.frame(a=14:16, b=letters[14:16], c=LETTERS[14:16], 40 | lat=c(52.58,53.45,52.4), lon=c(6.34,7.23,13.05)) 41 | popleaf(dat) 42 | dat$display <- popleaf(dat, 1:4) 43 | 44 | \dontrun{ # Excluded from CRAN checks 45 | library(leaflet) 46 | leaflet(dat) \%>\% addTiles() \%>\% addCircleMarkers(~lon, ~lat, popup=~display) 47 | } 48 | 49 | dat[1,1] <- "Very long string I'd rather have truncated" 50 | popleaf(dat, 1:3) 51 | popleaf(dat, 1:3, truncate=16) 52 | popleaf(dat, 1:3, truncate=16, tstring="--") 53 | 54 | } 55 | \seealso{ 56 | \code{\link{paste}} 57 | } 58 | \author{ 59 | Berry Boessenkool, \email{berry-b@gmx.de}, Apr 2017 60 | } 61 | \keyword{aplot} 62 | -------------------------------------------------------------------------------- /man/pretty2.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/pretty2.R 3 | \name{pretty2} 4 | \alias{pretty2} 5 | \title{Truncated pretty breakpoints} 6 | \usage{ 7 | pretty2(x, n = 5, force = FALSE, ...) 8 | } 9 | \arguments{ 10 | \item{x}{object with numeric values} 11 | 12 | \item{n}{desired number of values in \code{\link{pretty}}. DEFAULT: 5} 13 | 14 | \item{force}{Must output length equal n exactly? DEFAULT: FALSE} 15 | 16 | \item{\dots}{all other arguments in \code{\link{pretty}}.} 17 | } 18 | \description{ 19 | \code{\link{pretty}} with no values outside of x range 20 | } 21 | \details{ 22 | calculates \code{pretty(x)}, then removes the values that do not lie within 23 | \code{\link{range}(x)}.\cr If force=TRUE, range(x) is reduced step by step 24 | in a while loop until the condition is met. This is useful if you want 25 | exactly 2 labels on an \code{\link{axis}}. In order not to get stuck, the 26 | outer values are taken if there are more than n values within range(x). 27 | } 28 | \examples{ 29 | 30 | k <- c(135, 155, 120, 105, 140, 130, 190, 110) 31 | range(k) 32 | pretty(k) 33 | pretty2(k) 34 | 35 | pretty(c(0.2, 0.9), n=2) 36 | pretty2(c(0.2, 0.9), n=2) 37 | pretty2(c(0.2, 0.9), n=2, force=TRUE) 38 | 39 | } 40 | \seealso{ 41 | \code{\link{pretty}} , \code{\link{logVals}} 42 | } 43 | \author{ 44 | Berry Boessenkool, \email{berry-b@gmx.de}, Aug 2014 45 | } 46 | \keyword{dplot} 47 | -------------------------------------------------------------------------------- /man/rainbow2.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rainbow2.R 3 | \name{rainbow2} 4 | \alias{rainbow2} 5 | \title{Rainbow from blue to red} 6 | \usage{ 7 | rainbow2(n = 10, s = 1, v = 1, start = 0, end = 0.7, alpha = 1) 8 | } 9 | \arguments{ 10 | \item{n}{number of colors. DEFAULT: 10} 11 | 12 | \item{s, v}{saturation and value as in \code{\link{rainbow}}. DEFAULT: 1} 13 | 14 | \item{start}{start color. DEFAULT: 0} 15 | 16 | \item{end}{end color. DEFAULT: 0.7} 17 | 18 | \item{alpha}{transparency. DEFAULT: 1)} 19 | } 20 | \value{ 21 | A character vector of color names. 22 | } 23 | \description{ 24 | Reversed \code{\link{rainbow}} with different defaults, resulting in a color vector from blue (good) to red (bad) 25 | } 26 | \examples{ 27 | 28 | plot(1:10, pch=16, cex=2, col=rainbow2(10)) 29 | 30 | } 31 | \seealso{ 32 | \code{\link{seqPal}} for a better palette, \code{\link{rainbow}} 33 | } 34 | \author{ 35 | Berry Boessenkool, \email{berry-b@gmx.de}, Sept 2014 36 | } 37 | \keyword{color} 38 | \keyword{dplot} 39 | -------------------------------------------------------------------------------- /man/removeSpace.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/removeSpace.R 3 | \name{removeSpace} 4 | \alias{removeSpace} 5 | \title{Remove white spaces from strings} 6 | \usage{ 7 | removeSpace(x, begin = TRUE, end = TRUE, all = FALSE, ...) 8 | } 9 | \arguments{ 10 | \item{x}{Character string, can be a vector} 11 | 12 | \item{begin}{Logical. Remove leading spaces at the beginning of the character string? DEFAULT: TRUE} 13 | 14 | \item{end}{Logical. Remove trailing spaces at the end? DEFAULT: TRUE} 15 | 16 | \item{all}{Logical. Remove all spaces anywhere in the string? DEFAULT: FALSE} 17 | 18 | \item{\dots}{Further arguments passed to \code{\link{sub}} or \code{\link{gsub}}, like \code{ignore.case, perl, fixed, useBytes}.} 19 | } 20 | \value{ 21 | Character string (vector) 22 | } 23 | \description{ 24 | Remove leading and/or trailing white space from character strings 25 | } 26 | \note{ 27 | If all arguments are FALSE, the string is returned unchanged.\cr Not 28 | extensively tested yet, please mail me any problems... 29 | } 30 | \examples{ 31 | 32 | s <- c("space at end ", " white at begin", " both ", " special ^ ") 33 | removeSpace(s) 34 | trimws(s) 35 | 36 | # To add space, use: 37 | x <- c("ab","abcde") 38 | format(x) 39 | format(x, justify="centre") 40 | format(x, width=9) 41 | 42 | } 43 | \seealso{ 44 | \code{\link{sub}}, \code{\link{trimws}} since R 3.2.0 (April 2015) 45 | } 46 | \author{ 47 | Berry Boessenkool, \email{berry-b@gmx.de}, Dec 2014 48 | } 49 | \keyword{character} 50 | -------------------------------------------------------------------------------- /man/rescale.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rescale.R 3 | \name{rescale} 4 | \alias{rescale} 5 | \title{shift and scale a vector} 6 | \usage{ 7 | rescale(x, from = 0, to = 1) 8 | } 9 | \arguments{ 10 | \item{x}{Numerical vector of values to be mapped to a given range} 11 | 12 | \item{from}{output minimum. DEFAULT: 0} 13 | 14 | \item{to}{output maximum. DEFAULT: 1} 15 | } 16 | \value{ 17 | numeric vector, rescaled onto output range 18 | } 19 | \description{ 20 | rescale a numeric vector: map values linearly onto a given range 21 | } 22 | \examples{ 23 | 24 | rescale(10:15, 135, 200) 25 | rescale(10:15, 200, 135) 26 | rescale(10:15, to=c(1,5)) 27 | 28 | values <- rbeta(1e3, shape1=4, shape2=35) 29 | hist(rescale(values, 135, 200), breaks=25, col=3) 30 | 31 | } 32 | \references{ 33 | \url{https://stackoverflow.com/a/18303620} 34 | } 35 | \seealso{ 36 | \code{scales::rescale} 37 | } 38 | \author{ 39 | Berry Boessenkool, \email{berry-b@gmx.de}, Jan 2016 40 | } 41 | \keyword{manip} 42 | -------------------------------------------------------------------------------- /man/round0.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/round0.R 3 | \name{round0} 4 | \alias{round0} 5 | \title{Round numbers with leading and trailing zeros} 6 | \usage{ 7 | round0( 8 | x, 9 | digits = 0, 10 | pre = 2, 11 | width = digits + pre + ifelse(digits == 0, 0, 1), 12 | flag = 0, 13 | ... 14 | ) 15 | } 16 | \arguments{ 17 | \item{x}{Value(s)} 18 | 19 | \item{digits}{Number of digits (after decimal separator) to keep. DEFAULT: 0} 20 | 21 | \item{pre}{Minimum number of characters before the decimal separator. DEFAULT: 2} 22 | 23 | \item{width}{Total width (number of characters including dot). 24 | DEFAULT: digits+pre (+1 if needed)} 25 | 26 | \item{flag}{Flag. Could be "" for spaces. DEFAULT: "0"} 27 | 28 | \item{\dots}{Further arguments passed to \code{\link{formatC}}, 29 | except for "format".} 30 | } 31 | \value{ 32 | Character string vector 33 | } 34 | \description{ 35 | Round numbers and add leading + trailing zeros 36 | } 37 | \examples{ 38 | round0( pi*10^(-3:5), 2) 39 | stopifnot(round0(17.3, 2) == "17.30") 40 | round0(7.3) 41 | round0(c(7.3,777.1234), 2) 42 | round0(c(0.2,7.3,12.8), 2, pre=1) 43 | round0(c(0.2,7.3,12.8), 1, pre=3, flag="") # spaces instead of zeros 44 | 45 | } 46 | \seealso{ 47 | \code{\link{formatC}}, \code{\link{sprintf}} 48 | } 49 | \author{ 50 | Berry Boessenkool, \email{berry-b@gmx.de}, Jun 2017 51 | } 52 | -------------------------------------------------------------------------------- /man/runAxis.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/runAxis.R 3 | \name{runAxis} 4 | \alias{runAxis} 5 | \title{Label axis with typical running times} 6 | \usage{ 7 | runAxis(t = 3 * 60, int1 = 10, int2 = 5, side = 1, linarg = NULL, ...) 8 | } 9 | \arguments{ 10 | \item{t}{Maximum time in minutes} 11 | 12 | \item{int1}{Primary interval (for labels)} 13 | 14 | \item{int2}{Secondary interval (for lines)} 15 | 16 | \item{side}{Side of the plot to draw \code{\link{axis}} (1,2,3,4 = bottom, left, top, right)} 17 | 18 | \item{linarg}{List of arguments passed to \code{\link{abline}}} 19 | 20 | \item{\dots}{Further arguments passed to \code{\link{axis}}} 21 | } 22 | \value{ 23 | List with the positions and labels 24 | } 25 | \description{ 26 | Label a numerical axis (in minutes) with time units that are typical for running times (10 sec intervals) 27 | } 28 | \examples{ 29 | plot(1:200, xaxt="n") 30 | runAxis(t=200, int1=20, int2=10) 31 | 32 | } 33 | \seealso{ 34 | \code{\link{logAxis}}, \code{\link{monthAxis}} 35 | } 36 | \author{ 37 | Berry Boessenkool, \email{berry-b@gmx.de}, Jun 2016 38 | } 39 | \keyword{aplot} 40 | -------------------------------------------------------------------------------- /man/runRversions.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/runRversions.R 3 | \name{runRversions} 4 | \alias{runRversions} 5 | \title{Run code in several R versions} 6 | \usage{ 7 | runRversions( 8 | scpt = NULL, 9 | expr = NULL, 10 | path = "C:/Program Files/R/", 11 | vrns = dir(path, pattern = "R-"), 12 | exec = "/bin/Rscript.exe" 13 | ) 14 | } 15 | \arguments{ 16 | \item{scpt}{File path to script. DEFAULT: NULL} 17 | 18 | \item{expr}{Expression to be run. DEFAULT: NULL} 19 | 20 | \item{path}{Location of R versions. DEFAULT: "C:/Program Files/R/"} 21 | 22 | \item{vrns}{R Versions at path. DEFAULT: dir(path,pattern="R-")} 23 | 24 | \item{exec}{Local path to Rscript. DEFAULT: "/bin/Rscript.exe"} 25 | } 26 | \value{ 27 | Results from each run 28 | } 29 | \description{ 30 | Run code / script in several local R versions 31 | } 32 | \examples{ 33 | tfile <- tempfile(fileext=".R") 34 | cat( 35 | 'trace <- function() paste(sapply(sys.calls(),function(x) 36 | strsplit(deparse(x),"(", fixed=TRUE)[[1]][1]), collapse=" -> ") 37 | lower <- function(a) {message(trace(), " - msg with ", a+10); a} 38 | upper <- function(b) lower(b+5) 39 | upper(3)', file=tfile) 40 | 41 | # Don't actually run with example testing 42 | # out <- source(tfile) ; out$value # message + output 8 43 | # runRversions(tfile) 44 | # runRversions(expr=5+7) 45 | 46 | } 47 | \seealso{ 48 | \code{\link{help}} 49 | } 50 | \author{ 51 | Berry Boessenkool, \email{berry-b@gmx.de}, May 2022 52 | } 53 | -------------------------------------------------------------------------------- /man/runTime.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/runTime.R 3 | \name{runTime} 4 | \alias{runTime} 5 | \title{runnning time conversion} 6 | \usage{ 7 | runTime(d, t) 8 | } 9 | \arguments{ 10 | \item{d}{Numerical value: distance [km]} 11 | 12 | \item{t}{Charstring: time ["MM:SS"]} 13 | } 14 | \value{ 15 | list with time elements 16 | } 17 | \description{ 18 | display runnning times in useful units 19 | } 20 | \examples{ 21 | runTime(d=3.6, t="15:40") 22 | runTime(d=3.6, t="15:10") 23 | runTime(d=3.6, t="14:50") 24 | 25 | } 26 | \seealso{ 27 | \code{\link{runAxis}} 28 | } 29 | \author{ 30 | Berry Boessenkool, \email{berry-b@gmx.de}, Jun 2020 31 | } 32 | -------------------------------------------------------------------------------- /man/seqR.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/seqR.R 3 | \name{seqR} 4 | \alias{seqR} 5 | \title{seq with a range argument} 6 | \usage{ 7 | seqR(range, from = NA, to = NA, extend = 0, warn = TRUE, ...) 8 | } 9 | \arguments{ 10 | \item{range}{vector with 2 values (1st taken as \code{from}, 2nd as \code{to}) 11 | or more (the result is then always ascending).} 12 | 13 | \item{from}{start value of sequence. DEFAULT: NA (determined from range)} 14 | 15 | \item{to}{end value of sequence. DEFAULT: NA (determined from range)} 16 | 17 | \item{extend}{Factor \emph{f} passed to \code{\link{extendrange}}. DEFAULT: 0} 18 | 19 | \item{warn}{Logical: warn about non-numeric classes? DEFAULT: TRUE} 20 | 21 | \item{\dots}{further arguments passed to \code{\link{seq}}.} 22 | } 23 | \value{ 24 | Numeric vector. 25 | } 26 | \description{ 27 | sequence given by range or vector of values. 28 | } 29 | \examples{ 30 | 31 | seqR(range=c(12,6), by=-2) 32 | m <- c(41, 12, 38, 29, 50, 39, 22) 33 | seqR(m, len=6) 34 | # Takes min and max of range if the vector has more than two elements. 35 | 36 | seqR(range=c(12,6), by=-2, extend=0.1) 37 | # internaly calls extendrange with f=extend 38 | 39 | } 40 | \seealso{ 41 | \code{\link{seq}}, \code{\link{range}}, 42 | \url{https://web.archive.org/web/20190107005108/https://r.789695.n4.nabble.com/seq-range-argument-td4684627.html} 43 | } 44 | \author{ 45 | Berry Boessenkool, \email{berry-b@gmx.de}, Feb 2014 46 | } 47 | \keyword{datagen} 48 | -------------------------------------------------------------------------------- /man/showPal.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/pal.R 3 | \name{showPal} 4 | \alias{showPal} 5 | \title{show color palettes} 6 | \usage{ 7 | showPal(cex = 4, ...) 8 | } 9 | \arguments{ 10 | \item{cex}{Character EXpansion size (width of color bar). DEFAULT: 4} 11 | 12 | \item{\dots}{Arguments passed to \code{\link{par}}} 13 | } 14 | \description{ 15 | Plot examples of the sequential and diverging color palettes in this package. 16 | Do not use \code{rainbow}: \url{https://eagereyes.org/basics/rainbow-color-map} 17 | } 18 | \examples{ 19 | showPal() 20 | } 21 | \seealso{ 22 | \code{\link{seqPal}}, \code{\link{divPal}}, \code{\link{catPal}}, 23 | package \code{RColorBrewer}, 24 | \url{https://blog.datawrapper.de/which-color-scale-to-use-in-data-vis/} 25 | } 26 | \author{ 27 | Berry Boessenkool, \email{berry-b@gmx.de}, Apr 2016 28 | } 29 | \keyword{color} 30 | \keyword{dplot} 31 | -------------------------------------------------------------------------------- /man/smoothLines.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/smoothLines.R 3 | \name{smoothLines} 4 | \alias{smoothLines} 5 | \title{draw smoothed lines} 6 | \usage{ 7 | smoothLines(x, y, lwd = 1, col = 1, n = 5, alpha = 0.1, ...) 8 | } 9 | \arguments{ 10 | \item{x}{numerical. x-coordinates. x can be a matrix, then the y coordinates are taken from the second column} 11 | 12 | \item{y}{numerical. y-coordinates} 13 | 14 | \item{lwd}{single integer. line width} 15 | 16 | \item{col}{color. DEFAULT: 1 (black)} 17 | 18 | \item{n}{single integer. number of transparent lines overlayed with sinking line widths. DEFAULT: 5} 19 | 20 | \item{alpha}{Transparency of color. DEFAULT: 0.1 (very transparent)} 21 | 22 | \item{\dots}{further arguments as in \code{\link{lines}}} 23 | } 24 | \value{ 25 | none, draws lines 26 | } 27 | \description{ 28 | draw smoothed lines with an n-level partially transparent haze 29 | } 30 | \examples{ 31 | 32 | x <- 1:5 ; y <- c(0.31, 0.45, 0.84, 0.43, 0.25) 33 | plot(x,y) 34 | smoothLines(x,y) 35 | #png("smoothLines.png") 36 | par(mar=c(2,2,2,0)+.5) 37 | plot(1:100, las=1, type="n", main="usage of smoothLines(x,y, lwd, col, n, alpha ...)") 38 | abline(h=0:10*10, v=0:10*10, col=6); box() 39 | for(i in 0:9) { smoothLines(x=c(0,10,25,35), y=c(i*10, i*10, i*10+12, i*10+7), lwd=i) 40 | text(25, i*10+5, paste("n=5,lwd=", i, sep="")) } 41 | for(i in 0:9) { smoothLines(x=c(40,50,65,75), y=c(i*10, i*10, i*10+12, i*10+7), n=i) 42 | text(65, i*10+5, paste("n=",i,",lwd=1", sep="")) } 43 | for(i in 0:9/20) { smoothLines(x=c(80,90,105), y=c(i*200, i*200+12, i*200+12), alpha=i) 44 | text(90, i*200+10, paste("alpha=", i, sep=""), adj=0) } 45 | text(5,10, "default", adj=c(0.5,-0.2)); text(45,50, "default", adj=c(0.5,-0.2)) 46 | 47 | #dev.off() 48 | 49 | } 50 | \seealso{ 51 | \code{\link{lines}}, \code{\link{col2rgb}}, \code{\link{rgb}} 52 | } 53 | \author{ 54 | Berry Boessenkool, \email{berry-b@gmx.de}, 2011/2012 55 | } 56 | \keyword{aplot} 57 | -------------------------------------------------------------------------------- /man/sortDF.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/sortDF.R 3 | \name{sortDF} 4 | \alias{sortDF} 5 | \title{sort dataframes by column} 6 | \usage{ 7 | sortDF(df, col, decreasing = TRUE, quiet = FALSE, ...) 8 | } 9 | \arguments{ 10 | \item{df}{Data.frame to be sorted} 11 | 12 | \item{col}{Column (index or (un)quoted name) to be sorted by} 13 | 14 | \item{decreasing}{Logical: should highest value be on top? 15 | DEFAULT: TRUE (unlike \code{\link{order}}!)} 16 | 17 | \item{quiet}{Logical: suppress non-df warning? DEFAULT: FALSE} 18 | 19 | \item{\dots}{Further arguments passed to \code{\link{order}}, 20 | like eg \code{na.last or method}} 21 | } 22 | \value{ 23 | data.frame 24 | } 25 | \description{ 26 | sort a data.frame by column - basically just a wrapper for order 27 | } 28 | \examples{ 29 | sortDF(USArrests[USArrests$Murder>11,], Assault) 30 | sortDF(USArrests[USArrests$Murder>11,], "Assault") # safer within functions 31 | sortDF(USArrests[USArrests$Murder>11,], 3) 32 | 33 | } 34 | \seealso{ 35 | \code{\link{sort}}, \code{\link{order}}, 36 | \code{\link{insertRows}}, \code{\link{addRows}} 37 | } 38 | \author{ 39 | Berry Boessenkool, \email{berry-b@gmx.de}, June 2015 40 | } 41 | \keyword{arith} 42 | \keyword{manip} 43 | \keyword{univar} 44 | -------------------------------------------------------------------------------- /man/spiralDateAnim.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/spiralDateAnim.R 3 | \name{spiralDateAnim} 4 | \alias{spiralDateAnim} 5 | \title{Animated spiral graph} 6 | \usage{ 7 | spiralDateAnim( 8 | dates, 9 | values, 10 | data, 11 | steps = 100, 12 | sleep = 0, 13 | progbar = TRUE, 14 | ... 15 | ) 16 | } 17 | \arguments{ 18 | \item{dates, values, data}{Input as in \code{\link{spiralDate}}} 19 | 20 | \item{steps}{Number of steps (images) in animation. DEFAULT: 100} 21 | 22 | \item{sleep}{Pause time between frames, in seconds, passed to \code{\link{Sys.sleep}}. DEFAULT: 0} 23 | 24 | \item{progbar}{Should a progress bar be drawn? Useful if you have a large dataset or many steps. DEFAULT: TRUE} 25 | 26 | \item{\dots}{Further arguments passed to \code{\link{spiralDate}}} 27 | } 28 | \description{ 29 | Animation of (daily) time series along spiral 30 | } 31 | \examples{ 32 | 33 | set.seed(42) 34 | x <- as.Date("1985-01-01")+0:5000 35 | y <- cumsum(rnorm(5001))+50 36 | y <- y + sin(0:5000/366*2*pi)*max(abs(y))/2 37 | plot(x,y) 38 | 39 | spiralDateAnim(x,y, steps=10, sleep=0.01) # 0.05 might be smoother... 40 | 41 | \dontrun{ 42 | ## Rcmd check --as-cran doesn't like to open external devices such as pdf, 43 | ## so this example is excluded from running in the checks. 44 | pdf("spiralDateAnimation.pdf") 45 | spiralDateAnim(x,y, main="Example Transition", col=divPal(100), format=" ") 46 | dev.off() 47 | 48 | # if you have FFmpeg installed, you can use the animation package like this: 49 | library2(animation) 50 | saveVideo(spiralDateAnim(x,y, steps=300), video.name="spiral_anim.mp4", interval=0.1, 51 | ffmpeg="C:/Program Files/R/ffmpeg/bin/ffmpeg.exe") 52 | 53 | } 54 | 55 | } 56 | \seealso{ 57 | \code{\link{spiralDate}}, \code{\link{linLogHist}} 58 | } 59 | \author{ 60 | Berry Boessenkool, \email{berry-b@gmx.de}, May 2016 61 | } 62 | \keyword{aplot} 63 | \keyword{chron} 64 | \keyword{color} 65 | \keyword{hplot} 66 | -------------------------------------------------------------------------------- /man/sumatraInitialize.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/sumatraInitialize.R 3 | \name{sumatraInitialize} 4 | \alias{sumatraInitialize} 5 | \title{Set useful Sumatra PDF Viewer default settings} 6 | \usage{ 7 | sumatraInitialize( 8 | path = sumatraPaths()[1], 9 | roampath = sumatraPaths()[2], 10 | openfolder = TRUE 11 | ) 12 | } 13 | \arguments{ 14 | \item{path}{Folder (not file) that contains "SumatraPDF.exe". 15 | You need file writing permissions in the folder. 16 | DEFAULT: equivalent of "C:/Program Files/RStudio/resources/app/bin/sumatra"} 17 | 18 | \item{roampath}{Folder that will contain "SumatraPDF-settings.txt". 19 | DEFAULT: equivalent of "C:/Users/berry/AppData/Roaming/SumatraPDF"} 20 | 21 | \item{openfolder}{Logical: Open folders after writing the files? 22 | Uses \code{\link{openFile}()}. DEFAULT: TRUE} 23 | } 24 | \value{ 25 | path, invisibly 26 | } 27 | \description{ 28 | Set useful Sumatra PDF Viewer default settings. This will only work on windows. 29 | Existing files are renamed ("_old_n" appended), not overwritten.\cr 30 | At the given \code{path} with "SumatraPDF.exe", it creates "sumatrapdfrestrict.ini" with \code{SavePreferences = 1} and \code{FullscreenAccess = 1}.\cr 31 | At the given \code{roampath}, it creates "SumatraPDF-settings.txt" with \code{ShowToc = false} and \code{DefaultDisplayMode = single page}. 32 | \code{UiLanguage} gets filled in by Sumatra itself upon first opening. 33 | } 34 | \examples{ 35 | # sumatraInitialize() # only run in interactive mode 36 | 37 | } 38 | \seealso{ 39 | \code{\link{openPDF}}\cr 40 | \url{https://www.sumatrapdfreader.org/settings/settings.html}\cr 41 | \url{https://github.com/sumatrapdfreader/sumatrapdf/blob/master/docs/sumatrapdfrestrict.ini} 42 | } 43 | \author{ 44 | Berry Boessenkool, \email{berry-b@gmx.de}, May 2020, Nov 2023 45 | } 46 | \keyword{file} 47 | -------------------------------------------------------------------------------- /man/sumatraPaths.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/sumatraPaths.R 3 | \name{sumatraPaths} 4 | \alias{sumatraPaths} 5 | \title{Get Sumatra PDF Viewer paths} 6 | \usage{ 7 | sumatraPaths(open = FALSE) 8 | } 9 | \arguments{ 10 | \item{open}{open the folders? DEFAULT: FALSE} 11 | } 12 | \value{ 13 | paths 14 | } 15 | \description{ 16 | Get Sumatra paths for \code{\link{sumatraInitialize}}. This will only work on windows. 17 | } 18 | \examples{ 19 | sumatraPaths() 20 | } 21 | \seealso{ 22 | \code{\link{sumatraInitialize}} 23 | } 24 | \author{ 25 | Berry Boessenkool, \email{berry-b@gmx.de}, Jan 2024 26 | } 27 | -------------------------------------------------------------------------------- /man/testExamples.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/testExamples.R 3 | \name{testExamples} 4 | \alias{testExamples} 5 | \title{Test examples in a package} 6 | \usage{ 7 | testExamples( 8 | path = packagePath("."), 9 | commentDontrun = FALSE, 10 | selection = NULL, 11 | logfolder = "ExampleTestLogs", 12 | elogfile = "errors.txt", 13 | wlogfile = "warnings.txt", 14 | tlogfile = "times.txt", 15 | plotfile = "plots.pdf", 16 | tellcurrentfile = TRUE, 17 | telldocument = TRUE, 18 | ... 19 | ) 20 | } 21 | \arguments{ 22 | \item{path}{Path to package. For internal function \code{testExample}, 23 | path to a single Rd file. 24 | DEFAULT: \code{\link{packagePath}(".")}} 25 | 26 | \item{commentDontrun}{Logical. Should \\dontrun sections be excluded? 27 | DEFAULT: FALSE} 28 | 29 | \item{selection}{Optional: selection of files, e.g 1:10. DEFAULT: NULL} 30 | 31 | \item{logfolder}{Directory where to store the logfiles. Created if not 32 | existing. DEFAULT: "ExampleTestLogs"} 33 | 34 | \item{elogfile}{File to log errors in. (Appended to existing text). 35 | DEFAULT: "errors.txt"} 36 | 37 | \item{wlogfile}{File to log warnings and messages in. (Appended to existing text). 38 | DEFAULT: "warnings.txt"} 39 | 40 | \item{tlogfile}{File in which to write computing times. 41 | DEFAULT: "times.txt"} 42 | 43 | \item{plotfile}{File to log warnings and messages in. (Appended to existing text). 44 | DEFAULT: "plots.pdf"} 45 | 46 | \item{tellcurrentfile}{Logical: At the beginning of each file, message the 47 | name and current time in the console?} 48 | 49 | \item{telldocument}{Message reminder to run \code{devtools::document()}? 50 | DEFAULT: TRUE} 51 | 52 | \item{\dots}{Further arguments passed to internal function \code{testExample} 53 | and from there to \code{tools::\link{Rd2ex}}} 54 | } 55 | \value{ 56 | Logical indicating successful tests 57 | } 58 | \description{ 59 | Test all examples in a package 60 | } 61 | \examples{ 62 | # testExamples(selection=1:10) 63 | 64 | } 65 | \seealso{ 66 | The evaluate package 67 | } 68 | \author{ 69 | Berry Boessenkool, \email{berry-b@gmx.de}, Mar 2019 70 | } 71 | \keyword{package} 72 | -------------------------------------------------------------------------------- /man/timer.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/timer.R 3 | \name{timer} 4 | \alias{timer} 5 | \title{Timer alarm} 6 | \usage{ 7 | timer(interval = 20, n = 15, write = FALSE) 8 | } 9 | \arguments{ 10 | \item{interval}{\code{\link{alarm}} interval in seconds. DEFAULT: 20} 11 | 12 | \item{n}{number of alarm signals to be given. DEFAULT: 15} 13 | 14 | \item{write}{Should the actual estimated time be written for overhead computing time control purposes? DEFAULT: FALSE} 15 | } 16 | \value{ 17 | none 18 | } 19 | \description{ 20 | Beeps in a given interval and gives a progress bar in the console 21 | } 22 | \details{ 23 | defaults to practice useR lightning talks: 15 slides, each shown 20 secs, change automatically 24 | } 25 | \examples{ 26 | 27 | \dontrun{## Skip time consuming checks on CRAN 28 | timer(interval=0.5, n=3) 29 | timer(interval=0.2, n=8, write=TRUE) # a slight deviation occurs for a large n 30 | # timer() # to practice lightning talks at useR! conferences 31 | } 32 | 33 | } 34 | \references{ 35 | \url{https://user2015.math.aau.dk/lightning_talks} 36 | } 37 | \seealso{ 38 | \code{\link{alarm}}, \code{\link{Sys.sleep}}, \code{\link{txtProgressBar}} 39 | } 40 | \author{ 41 | Berry Boessenkool, \email{berry-b@gmx.de}, June 2015 42 | } 43 | \keyword{chron} 44 | \keyword{utilities} 45 | -------------------------------------------------------------------------------- /man/tmessage.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tmessage.R 3 | \name{tmessage} 4 | \alias{tmessage} 5 | \alias{twarning} 6 | \alias{tstop} 7 | \title{messages with call trace} 8 | \usage{ 9 | tmessage(..., skip = 0) 10 | 11 | twarning(..., skip = 0, call. = FALSE, noBreaks. = TRUE) 12 | 13 | tstop(..., skip = 0, call. = FALSE) 14 | } 15 | \arguments{ 16 | \item{...}{Passed to \link{message}, \link{warning} or \link{stop}} 17 | 18 | \item{skip}{Number of tracing levels to exclude. Default: 0} 19 | 20 | \item{call.}{include twarning/tstop call? DEFAULT: FALSE (unlike the originals)} 21 | 22 | \item{noBreaks.}{reduce line breaks if \code{options(warn=1)}? 23 | DEFAULT: TRUE (unlike the original)} 24 | } 25 | \value{ 26 | NULL, as per \link{message}, \link{warning} or \link{stop} 27 | } 28 | \description{ 29 | \link{message}, \link{warning} or \link{stop} with a call trace prepended 30 | } 31 | \examples{ 32 | lower <- function(a, s) {tmessage("some stuff with ", a+10, skip=s); a} 33 | upper <- function(b, skip=0) lower(b+5, skip) 34 | upper(3) # upper -> lower: some stuff with 18 35 | upper(3, skip=1) # no "lower" in trace 36 | upper(3, skip=-1) # upper -> lower -> tmessage: some stuff with 18 37 | tmessage("Some message", " to be displayed") 38 | lower <- function(a, s) {twarning("some stuff with ", a+10, skip=s); a} 39 | upper(7) 40 | oop <- options(warn=1) 41 | upper(7) # Warning: upper -> lower: some [] no line break :) 42 | options(oop) ; rm(oop) 43 | lower <- function(a, s) {tstop("some stuff with ", a+10, skip=s); a} 44 | try( upper(7) ) # Error : try -> upper -> lower: some stuff with 22 45 | } 46 | \seealso{ 47 | \link{traceCall} for the generation of the trace 48 | } 49 | -------------------------------------------------------------------------------- /man/traceCall.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/traceCall.R 3 | \name{traceCall} 4 | \alias{traceCall} 5 | \title{call stack of a function} 6 | \usage{ 7 | traceCall( 8 | skip = 0, 9 | prefix = "\\nCall stack: ", 10 | suffix = "\\n", 11 | vigremove = TRUE, 12 | shiremove = TRUE, 13 | mesremove = TRUE 14 | ) 15 | } 16 | \arguments{ 17 | \item{skip}{Number of levels to skip in \code{\link{sys.calls}}} 18 | 19 | \item{prefix}{Prefix prepended to the output character string. DEFAULT: "\\nCall stack: "} 20 | 21 | \item{suffix}{Suffix appended to the end of the output. DEFAULT: "\\n"} 22 | 23 | \item{vigremove}{Logical: remove call created using devtools::build_vignettes()? 24 | DEFAULT: TRUE} 25 | 26 | \item{shiremove}{Logical: remove shiny::runApp ... renderPlot? DEFAULT: TRUE} 27 | 28 | \item{mesremove}{Logical: remove call part from \code{\link{.makeMessage}}? 29 | DEFAULT: TRUE} 30 | } 31 | \value{ 32 | Character string with the call stack 33 | } 34 | \description{ 35 | trace the call stack e.g. for error checking and format output for do.call levels 36 | } 37 | \examples{ 38 | lower <- function(a, s) {warning(traceCall(s, mesremove=FALSE), "stupid berry warning: ", a+10); a} 39 | upper <- function(b, skip=0) lower(b+5, skip) 40 | upper(3) 41 | 42 | # Since 2022-05-04, use tmessage / twarning / tstop instead! 43 | 44 | upper(3, skip=1) # traceCall skips last level (R3: warning, R4.1: .makeMessage, R4.2: lapply) 45 | upper(3, skip=6) # now the stack is empty 46 | d <- tryStack(upper("four"), silent=TRUE) 47 | inherits(d, "try-error") 48 | cat(d) 49 | 50 | lower <- function(a,...) {warning(traceCall(1, prefix="in ", suffix=": "), 51 | "How to use traceCall in functions ", call.=FALSE); a} 52 | upper(3) 53 | 54 | } 55 | \seealso{ 56 | \code{\link{tmessage}}, \code{\link{tryStack}}, \code{\link{checkFile}} for example usage 57 | } 58 | \author{ 59 | Berry Boessenkool, \email{berry-b@gmx.de}, Sep 2016 + March 2017 60 | } 61 | \keyword{error} 62 | \keyword{programming} 63 | -------------------------------------------------------------------------------- /man/truncMessage.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/truncMessage.R 3 | \name{truncMessage} 4 | \alias{truncMessage} 5 | \title{truncate message parts} 6 | \usage{ 7 | truncMessage( 8 | x, 9 | ntrunc = 3, 10 | prefix = "s", 11 | midfix = " ", 12 | altnix = "'", 13 | sep = ", " 14 | ) 15 | } 16 | \arguments{ 17 | \item{x}{Character vector} 18 | 19 | \item{ntrunc}{Integer: number of elements printed before truncation. DEFAULT: 3} 20 | 21 | \item{prefix}{Character: Prefix added if \code{length(x)>1}. DEFAULT: "s"} 22 | 23 | \item{midfix}{Character: string added after prefix OR before first altnix. DEFAULT: " "} 24 | 25 | \item{altnix}{Character: Alternative string padded around x if \code{length(x)==1}. 26 | DEFAULT: "'"} 27 | 28 | \item{sep}{Character: Separator between elements. DEFAULT: ", "} 29 | } 30 | \value{ 31 | Character string 32 | } 33 | \description{ 34 | truncate long vectors for messages 35 | } 36 | \examples{ 37 | truncMessage("hi") 38 | message("listing name", truncMessage( "hi" ), ".") 39 | message("listing name", truncMessage(paste0("hi",1:10)), ".") 40 | truncMessage(paste0("hi",1:10), ntrunc=1) 41 | truncMessage(paste0("hi",1:10), ntrunc=2, prefix="", midfix="") 42 | truncMessage(paste0("hi",1:10), ntrunc=8, prefix="files _ ") 43 | 44 | } 45 | \seealso{ 46 | \code{\link{message}} 47 | } 48 | \author{ 49 | Berry Boessenkool, \email{berry-b@gmx.de}, Nov 2016 50 | } 51 | \keyword{character} 52 | -------------------------------------------------------------------------------- /man/write.tab.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/write.tab.R 3 | \name{write.tab} 4 | \alias{write.tab} 5 | \title{write table with different defaults} 6 | \usage{ 7 | write.tab( 8 | x, 9 | file = NULL, 10 | sep = "\\t", 11 | name_rn = NULL, 12 | row.names = FALSE, 13 | col.names = !is.null(colnames(x)), 14 | quote = FALSE, 15 | fileEncoding = "UTF-8", 16 | open = TRUE, 17 | ... 18 | ) 19 | } 20 | \arguments{ 21 | \item{x}{Objekt to be written.} 22 | 23 | \item{file}{Filename. DEFAULT: NULL = [name of x].txt} 24 | 25 | \item{sep}{Column separator. DEFAULT: "\\t"} 26 | 27 | \item{name_rn}{If not NULL, this will be used as the name for a prepended 28 | column with the rownames. DEFAULT: NULL} 29 | 30 | \item{row.names}{Should rownames be written in a pre-column that will 31 | mess up alignment with column names? 32 | Use \code{name_rn} instead. DEFAULT: FALSE} 33 | 34 | \item{col.names}{Should colnames be written? 35 | DEFAULT: TRUE if x has colnames} 36 | 37 | \item{quote}{Write quatation marks around charstrings? DEFAULT: FALSE} 38 | 39 | \item{fileEncoding}{Encoding of charstrings. DEFAULT: "UTF-8"} 40 | 41 | \item{open}{Try to open the output file? DEFAULT: TRUE} 42 | 43 | \item{\dots}{Further arguments passed to \code{\link{write.table}}} 44 | } 45 | \value{ 46 | full filename 47 | } 48 | \description{ 49 | calls write.table with (personally) useful default values for the arguments. 50 | if \code{open=TRUE}, tries to open the file in the default txt viewer. 51 | } 52 | \examples{ 53 | # Don't run on CRAN test machines: 54 | \dontrun{ 55 | write.tab(iris) 56 | write.tab(iris, "otherfile.txt") 57 | write.tab(freeny) 58 | write.tab(freeny, name_rn="Time") 59 | unlink("iris.txt") 60 | unlink("otherfile.txt") 61 | unlink("freeny.txt") 62 | } 63 | } 64 | \seealso{ 65 | \code{\link{write.tab}} 66 | } 67 | \author{ 68 | Berry Boessenkool, \email{berry-b@gmx.de}, Sep 2021 69 | } 70 | \keyword{file} 71 | -------------------------------------------------------------------------------- /man/yearPlot.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/yearPlot.R 3 | \name{yearPlot} 4 | \alias{yearPlot} 5 | \title{annual plot} 6 | \usage{ 7 | yearPlot( 8 | dates, 9 | values, 10 | data, 11 | ylim = NULL, 12 | shift = 0, 13 | janline = TRUE, 14 | add = FALSE, 15 | months = substr(month.abb, 1, 1), 16 | xlab = "", 17 | ylab = "", 18 | zlab = "", 19 | ... 20 | ) 21 | } 22 | \arguments{ 23 | \item{dates}{Dates, in any format coerced by \code{\link{as.Date}}.} 24 | 25 | \item{values}{Values to be mapped in color with \code{\link{colPoints}}} 26 | 27 | \item{data}{Optional: data.frame from which to use dates and values.} 28 | 29 | \item{ylim}{(reverse) date range in numerical years. 30 | DEFAULT: NULL (computed from \code{dates} internally)} 31 | 32 | \item{shift}{Number of days to move the year-break to. 33 | E.g. shift=61 for German hydrological year (Nov to Oct). DEFAULT: 0} 34 | 35 | \item{janline}{Logical: Should vertical line be plotted at 36 | January 1st if \code{shift!=0}? DEFAULT: TRUE} 37 | 38 | \item{add}{Logical. Add to existing plot? DEFAULT: FALSE} 39 | 40 | \item{months}{Labels for the months. DEFAULT: J,F,M,A,M,J,J,A,S,O,N,D} 41 | 42 | \item{xlab, ylab, zlab}{Axis and legend labels. DEFAULT: ""} 43 | 44 | \item{\dots}{Further arguments passed to \code{\link{colPoints}} like 45 | legend, pch, main, xaxs, ...} 46 | } 47 | \value{ 48 | invisible list with coordinates 49 | } 50 | \description{ 51 | Visualize seasonality of time series 52 | } 53 | \examples{ 54 | qfile <- system.file("extdata/discharge39072.csv", package="berryFunctions") 55 | Q <- read.table(qfile, skip=19, header=TRUE, sep=",", fill=TRUE)[,1:2] 56 | Q$data <- as.Date(Q$data) 57 | yearPlot(data, last, data=Q) 58 | yearPlot(as.Date(c("2011-06-07","2009-03-25")), 1:2, add=TRUE, pch=3, col=1, legend=FALSE) 59 | yearPlot(data, last, data=Q, shift=61) 60 | yearPlot(data, last, data=Q, ylim=c(2015,2001)) 61 | 62 | } 63 | \seealso{ 64 | \code{\link{seasonality}}, \code{\link{colPoints}}, 65 | } 66 | \author{ 67 | Berry Boessenkool, \email{berry-b@gmx.de}, Sept 2019 68 | } 69 | \keyword{aplot} 70 | -------------------------------------------------------------------------------- /man/yearSample.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/yearSample.R 3 | \name{yearSample} 4 | \alias{yearSample} 5 | \title{Nonrandom year with sample} 6 | \usage{ 7 | yearSample(year) 8 | } 9 | \arguments{ 10 | \item{year}{4 digit numerical year.} 11 | } 12 | \value{ 13 | \code{\link{cat}}s command into the console that can be copypasted to anyone's R script. 14 | } 15 | \description{ 16 | Nerdy way to wish someone a happy new year by using sample 17 | } 18 | \details{ 19 | Nerdy way to wish someone a happy new year, eg:\cr 20 | Have a great \cr 21 | \code{set.seed(1244); sample(0:9,4,T)} 22 | } 23 | \examples{ 24 | 25 | yearSample(2016) 26 | # Have a nerdy 27 | set.seed(12353); sample(0:9, 4, replace=TRUE) 28 | 29 | } 30 | \seealso{ 31 | \code{\link{nameSample}} to impress with "randomly" finding a name, 32 | \code{\link{set.seed}}, \code{\link{sample}}, \code{\link{letters}} 33 | } 34 | \author{ 35 | Berry Boessenkool, \email{berry-b@gmx.de}, April 2014 36 | } 37 | -------------------------------------------------------------------------------- /zz_berryFunctions.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | ProjectId: c09730d0-d972-44db-8bdd-525e1f212ef2 3 | 4 | RestoreWorkspace: No 5 | SaveWorkspace: No 6 | AlwaysSaveHistory: Default 7 | 8 | EnableCodeIndexing: Yes 9 | UseSpacesForTab: Yes 10 | NumSpacesForTab: 1 11 | Encoding: UTF-8 12 | 13 | RnwWeave: knitr 14 | LaTeX: pdfLaTeX 15 | 16 | AutoAppendNewline: Yes 17 | 18 | BuildType: Package 19 | PackageUseDevtools: Yes 20 | PackageInstallArgs: --no-multiarch --with-keep.source 21 | PackageRoxygenize: rd,collate,namespace 22 | --------------------------------------------------------------------------------