Skip to content

Commit b01d90f

Browse files
committed
added numextractall
1 parent d206945 commit b01d90f

File tree

6 files changed

+57
-2
lines changed

6 files changed

+57
-2
lines changed

DESCRIPTION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: esmisc
22
Type: Package
33
Title: Misc Functions of Eduard Szöcs
4-
Version: 0.0.3.9001
4+
Version: 0.0.3.9002
55
Date: 2017-01-10
66
Authors@R: c(person("Eduard", "Szöcs", role = c("aut", "cre"),
77
email = "[email protected]"))

NAMESPACE

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Generated by roxygen2: do not edit by hand
22

33
export(geomean)
4+
export(numextractall)
45
export(read_regnie)
56
export(theme_edi)
67
import(ggplot2)

NEWS

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ esmisc 0.0.4
44

55
NEW FEATURES
66

7-
* added function for geometric mean
7+
* added geomean() for geometric mean
8+
* added numextractall() to extract numeric values from a string
89

910
MINOR IMPROVEMENTS
1011

R/numextractall.R

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#' Extract numbers from string
2+
#'
3+
#' Extract numbers from string
4+
#'
5+
#' @param x string
6+
#' @return numeric vector
7+
#' @references \url{ http://stackoverflow.com/questions/19252663/extracting-decimal-numbers-from-a-string}
8+
#' @export
9+
#' @examples
10+
#' numextractall('1 2 3')
11+
#' numextractall('1,2,3')
12+
#' numextractall('1;2,3 4')
13+
#' numextractall('1;2,3 4,46')
14+
numextractall <- function(x) {
15+
as.numeric(unlist(regmatches(x, gregexpr("[[:digit:]]+\\.*[[:digit:]]*", x)),
16+
use.names = FALSE))
17+
}

man/numextractall.Rd

+26
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-numextractall.R

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
context("numextractall")
2+
3+
4+
test_that('numextractall works', {
5+
expect_equal(numextractall('1 2 3'), c(1, 2, 3))
6+
expect_equal(numextractall('1,2,3'), c(1, 2, 3))
7+
expect_equal(numextractall('1;2,3 4'), c(1, 2, 3, 4))
8+
expect_equal(numextractall('1;2,3 4,46'), c(1, 2, 3, 4, 46))
9+
})
10+

0 commit comments

Comments
 (0)