mirror of
https://github.com/agdamsbo/stRoke.git
synced 2024-11-22 21:10:23 +01:00
Compare commits
No commits in common. "af426afef8b776950c888cdcc1faa092f9264e26" and "163e9708657222c5902d7541d5831eb34b210b36" have entirely different histories.
af426afef8
...
163e970865
@ -1,7 +1,6 @@
|
|||||||
# Generated by roxygen2: do not edit by hand
|
# Generated by roxygen2: do not edit by hand
|
||||||
|
|
||||||
S3method(print,win_Prob)
|
S3method(print,win_Prob)
|
||||||
export(add_padding)
|
|
||||||
export(age_calc)
|
export(age_calc)
|
||||||
export(chunks_of_n)
|
export(chunks_of_n)
|
||||||
export(ci_plot)
|
export(ci_plot)
|
||||||
|
2
NEWS.md
2
NEWS.md
@ -8,8 +8,6 @@
|
|||||||
|
|
||||||
* NEW: `str_extract()` will extract the substring of a character string given by a regex pattern. Came to be as a helper function for labelling chunks in `chunks_of_n()`, but will be useful on its own. Other functions doing the same exists, but this is my take only using base _R_. Draws on `REDCapCAST::strsplitx()`, where splits can be performed around a pattern.
|
* NEW: `str_extract()` will extract the substring of a character string given by a regex pattern. Came to be as a helper function for labelling chunks in `chunks_of_n()`, but will be useful on its own. Other functions doing the same exists, but this is my take only using base _R_. Draws on `REDCapCAST::strsplitx()`, where splits can be performed around a pattern.
|
||||||
|
|
||||||
* NEW: `add_padding()` was created out of frustration. I wanted to add padding using `sprintf("%0s",string)`, in examples for the above, but it would fail when rendering on Windows. Say hello to another function. Just very small. Defaults to adding leading zeros, to get all string to equal length with the longer string supplied.
|
|
||||||
|
|
||||||
* Deprecation: `ds2dd()` moved to `REDCapCAST::ds2dd()` as this is where it belongs.
|
* Deprecation: `ds2dd()` moved to `REDCapCAST::ds2dd()` as this is where it belongs.
|
||||||
|
|
||||||
# stRoke 23.6.3
|
# stRoke 23.6.3
|
||||||
|
@ -1,38 +0,0 @@
|
|||||||
#' Add padding to string
|
|
||||||
#'
|
|
||||||
#' @param d vector of strings or numbers
|
|
||||||
#' @param length final string length
|
|
||||||
#' @param after if padding should be added after as opposed to default before
|
|
||||||
#' @param pad padding string of length 1
|
|
||||||
#'
|
|
||||||
#' @return vector or character strings of same length.
|
|
||||||
#' @export
|
|
||||||
#'
|
|
||||||
#' @examples
|
|
||||||
#' add_padding(sample(1:200,5))
|
|
||||||
add_padding <- function(d,length=NULL,after=FALSE,pad="0"){
|
|
||||||
if (!is.vector(d)) {
|
|
||||||
stop("Please supply vector")
|
|
||||||
}
|
|
||||||
|
|
||||||
if (nchar(pad)!=1) {
|
|
||||||
stop("Padding value should be just a single character or digit")
|
|
||||||
}
|
|
||||||
|
|
||||||
ns <- nchar(d)
|
|
||||||
|
|
||||||
if (is.null(length)){
|
|
||||||
l <- max(ns)
|
|
||||||
} else {
|
|
||||||
l <- length
|
|
||||||
}
|
|
||||||
|
|
||||||
ps <- unlist(lapply(l-ns,function(i){
|
|
||||||
paste(rep(pad,i),collapse="")}))
|
|
||||||
|
|
||||||
if (after) {
|
|
||||||
paste0(d,ps)
|
|
||||||
} else {
|
|
||||||
paste0(ps,d)
|
|
||||||
}
|
|
||||||
}
|
|
@ -14,7 +14,7 @@
|
|||||||
#' tail(chunks_of_n(seq_len(100),7),3)
|
#' tail(chunks_of_n(seq_len(100),7),3)
|
||||||
#' tail(chunks_of_n(seq_len(100),7,even=TRUE),3)
|
#' tail(chunks_of_n(seq_len(100),7,even=TRUE),3)
|
||||||
#' ds <- data.frame(nm=paste0("Sub",
|
#' ds <- data.frame(nm=paste0("Sub",
|
||||||
#' add_padding(rownames(stRoke::talos))),stRoke::talos)
|
#' sprintf("%03s", rownames(stRoke::talos))),stRoke::talos)
|
||||||
#' head(chunks_of_n(ds,7,pattern="Sub[0-9]{3}",label="grp"),2)
|
#' head(chunks_of_n(ds,7,pattern="Sub[0-9]{3}",label="grp"),2)
|
||||||
#' ## Please notice that no sorting is performed. This is on purpose to preserve
|
#' ## Please notice that no sorting is performed. This is on purpose to preserve
|
||||||
#' ## original sorting. If sorting is intended, try something like this:
|
#' ## original sorting. If sorting is intended, try something like this:
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
[![Page deployed](https://github.com/agdamsbo/stRoke/actions/workflows/pages/pages-build-deployment/badge.svg)](https://github.com/agdamsbo/stRoke/actions/workflows/pages/pages-build-deployment)
|
[![Page deployed](https://github.com/agdamsbo/stRoke/actions/workflows/pages/pages-build-deployment/badge.svg)](https://github.com/agdamsbo/stRoke/actions/workflows/pages/pages-build-deployment)
|
||||||
[![Codecov test coverage](https://codecov.io/gh/agdamsbo/stRoke/branch/main/graph/badge.svg)](https://app.codecov.io/gh/agdamsbo/stRoke?branch=main)
|
[![Codecov test coverage](https://codecov.io/gh/agdamsbo/stRoke/branch/main/graph/badge.svg)](https://app.codecov.io/gh/agdamsbo/stRoke?branch=main)
|
||||||
[![CRAN downloads](https://cranlogs.r-pkg.org/badges/grand-total/stRoke)](https://cran.r-project.org/package=stRoke)
|
[![CRAN downloads](https://cranlogs.r-pkg.org/badges/grand-total/stRoke)](https://cran.r-project.org/package=stRoke)
|
||||||
|
[![R-CMD-check](https://github.com/agdamsbo/stRoke/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/agdamsbo/stRoke/actions/workflows/R-CMD-check.yaml)
|
||||||
<!-- badges: end -->
|
<!-- badges: end -->
|
||||||
|
|
||||||
# stRoke package <img src="man/figures/logo.png" align="right" />
|
# stRoke package <img src="man/figures/logo.png" align="right" />
|
||||||
|
@ -5,10 +5,10 @@ coverage:
|
|||||||
project:
|
project:
|
||||||
default:
|
default:
|
||||||
target: auto
|
target: auto
|
||||||
threshold: .1%
|
threshold: 1%
|
||||||
informational: true
|
informational: true
|
||||||
patch:
|
patch:
|
||||||
default:
|
default:
|
||||||
target: auto
|
target: auto
|
||||||
threshold: .1%
|
threshold: 1%
|
||||||
informational: true
|
informational: true
|
||||||
|
@ -1,26 +0,0 @@
|
|||||||
% Generated by roxygen2: do not edit by hand
|
|
||||||
% Please edit documentation in R/add_padding.R
|
|
||||||
\name{add_padding}
|
|
||||||
\alias{add_padding}
|
|
||||||
\title{Add padding to string}
|
|
||||||
\usage{
|
|
||||||
add_padding(d, length = NULL, after = FALSE, pad = "0")
|
|
||||||
}
|
|
||||||
\arguments{
|
|
||||||
\item{d}{vector of strings or numbers}
|
|
||||||
|
|
||||||
\item{length}{final string length}
|
|
||||||
|
|
||||||
\item{after}{if padding should be added after as opposed to default before}
|
|
||||||
|
|
||||||
\item{pad}{padding string of length 1}
|
|
||||||
}
|
|
||||||
\value{
|
|
||||||
vector or character strings of same length.
|
|
||||||
}
|
|
||||||
\description{
|
|
||||||
Add padding to string
|
|
||||||
}
|
|
||||||
\examples{
|
|
||||||
add_padding(sample(1:200,5))
|
|
||||||
}
|
|
@ -28,7 +28,7 @@ Split to chunks of size n
|
|||||||
tail(chunks_of_n(seq_len(100),7),3)
|
tail(chunks_of_n(seq_len(100),7),3)
|
||||||
tail(chunks_of_n(seq_len(100),7,even=TRUE),3)
|
tail(chunks_of_n(seq_len(100),7,even=TRUE),3)
|
||||||
ds <- data.frame(nm=paste0("Sub",
|
ds <- data.frame(nm=paste0("Sub",
|
||||||
add_padding(rownames(stRoke::talos))),stRoke::talos)
|
sprintf("\%03s", rownames(stRoke::talos))),stRoke::talos)
|
||||||
head(chunks_of_n(ds,7,pattern="Sub[0-9]{3}",label="grp"),2)
|
head(chunks_of_n(ds,7,pattern="Sub[0-9]{3}",label="grp"),2)
|
||||||
## Please notice that no sorting is performed. This is on purpose to preserve
|
## Please notice that no sorting is performed. This is on purpose to preserve
|
||||||
## original sorting. If sorting is intended, try something like this:
|
## original sorting. If sorting is intended, try something like this:
|
||||||
|
@ -1,17 +0,0 @@
|
|||||||
test_that("chunks_of_n returns correct", {
|
|
||||||
expect_length(add_padding(sample(1:200,5)),5)
|
|
||||||
|
|
||||||
expect_equal(nchar(add_padding(sample(1:200,5),5)), rep(5,5))
|
|
||||||
|
|
||||||
expect_equal(nchar(add_padding(
|
|
||||||
sample(1:200, 5), length = 5, after = TRUE
|
|
||||||
)), rep(5, 5))
|
|
||||||
|
|
||||||
|
|
||||||
## Errors
|
|
||||||
expect_error(add_padding(matrix(sample(1:200,5)),5))
|
|
||||||
|
|
||||||
expect_error(add_padding(matrix(sample(1:200,5)),5,pad = "123"))
|
|
||||||
|
|
||||||
|
|
||||||
})
|
|
@ -6,29 +6,22 @@ test_that("chunks_of_n returns correct", {
|
|||||||
use.names = FALSE), c(6, 6, 6, 6, 6))
|
use.names = FALSE), c(6, 6, 6, 6, 6))
|
||||||
|
|
||||||
# This is the example from the function, but I believe it fails in GitHub testing
|
# This is the example from the function, but I believe it fails in GitHub testing
|
||||||
ds <- data.frame(nm = paste0("Sub",
|
# ds <- data.frame(nm = paste0("Sub",
|
||||||
add_padding(rownames(stRoke::talos))),
|
# sprintf("%03s", rownames(stRoke::talos))),
|
||||||
stRoke::talos)
|
|
||||||
|
|
||||||
# ds <- data.frame(nm = paste0("Sub",rownames(stRoke::talos)),
|
|
||||||
# stRoke::talos)
|
# stRoke::talos)
|
||||||
|
|
||||||
|
ds <- data.frame(nm = paste0("Sub",rownames(stRoke::talos)),
|
||||||
|
stRoke::talos)
|
||||||
|
|
||||||
expect_equal(head(names(chunks_of_n(ds, 7,
|
expect_equal(head(names(chunks_of_n(ds, 7,
|
||||||
pattern = "Sub[0-9]{3}", label = "grp")),
|
pattern = "Sub([0-9]+)", label = "grp")),
|
||||||
1),"grp-Sub038-Sub011")
|
1),"grp-Sub38-Sub11")
|
||||||
|
|
||||||
expect_equal(
|
expect_equal(
|
||||||
ds[order(ds$nm),] |>
|
ds[order(as.numeric(rownames(stRoke::talos))), ] |>
|
||||||
chunks_of_n(7, pattern = "Sub([0-9]+)", label = "grp") |>
|
chunks_of_n(7, pattern = "Sub([0-9]+)", label = "grp") |>
|
||||||
head(1) |> names(),
|
head(1) |> names(),
|
||||||
"grp-Sub001-Sub020"
|
"grp-Sub1-Sub20"
|
||||||
)
|
|
||||||
|
|
||||||
expect_equal(
|
|
||||||
ds[order(ds$nm),] |>
|
|
||||||
chunks_of_n(7, pattern = "Sub[0-9]{3}", label = "grp") |>
|
|
||||||
head(1) |> names(),
|
|
||||||
"grp-Sub001-Sub020"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
## Errors
|
## Errors
|
||||||
@ -43,23 +36,23 @@ test_that("n_chunks returns correct", {
|
|||||||
expect_equal(lengths(n_chunks(seq_len(30), 7, even = TRUE),
|
expect_equal(lengths(n_chunks(seq_len(30), 7, even = TRUE),
|
||||||
use.names = FALSE), rep(5,6))
|
use.names = FALSE), rep(5,6))
|
||||||
|
|
||||||
## This is the example from the function, but I believe it fails in GitHub testing
|
# This is the example from the function, but I believe it fails in GitHub testing
|
||||||
ds <- data.frame(nm = paste0("Sub",
|
# ds <- data.frame(nm = paste0("Sub",
|
||||||
add_padding(rownames(stRoke::talos))),
|
# sprintf("%03s", rownames(stRoke::talos))),
|
||||||
stRoke::talos)
|
|
||||||
|
|
||||||
# ds <- data.frame(nm = paste0("Sub",rownames(stRoke::talos)),
|
|
||||||
# stRoke::talos)
|
# stRoke::talos)
|
||||||
|
|
||||||
|
ds <- data.frame(nm = paste0("Sub",rownames(stRoke::talos)),
|
||||||
|
stRoke::talos)
|
||||||
|
|
||||||
expect_equal(head(names(n_chunks(ds, 7,
|
expect_equal(head(names(n_chunks(ds, 7,
|
||||||
pattern = "Sub([0-9]+)", label = "grp")),
|
pattern = "Sub([0-9]+)", label = "grp")),
|
||||||
1),"grp-Sub038-Sub603")
|
1),"grp-Sub38-Sub603")
|
||||||
|
|
||||||
expect_equal(
|
expect_equal(
|
||||||
ds[order(ds$nm), ] |>
|
ds[order(as.numeric(rownames(stRoke::talos))), ] |>
|
||||||
n_chunks(7, pattern = "Sub([0-9]+)", label = "grp") |>
|
n_chunks(7, pattern = "Sub([0-9]+)", label = "grp") |>
|
||||||
head(1) |> names(),
|
head(1) |> names(),
|
||||||
"grp-Sub001-Sub072"
|
"grp-Sub1-Sub72"
|
||||||
)
|
)
|
||||||
|
|
||||||
## Errors
|
## Errors
|
||||||
|
Loading…
Reference in New Issue
Block a user