Skip to content

Commit bda2115

Browse files
committed
Add functions for minimum, maximum, and range calculations (fpmin, fpmax, prange) with NA handling in R
1 parent 887210d commit bda2115

File tree

5 files changed

+446
-2
lines changed

5 files changed

+446
-2
lines changed

NAMESPACE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
useDynLib(kit, .registration = TRUE)
22

33
export(
4-
charToFact, count, countNA, countOccur, fduplicated, fpos, funique, iif, nif, nswitch,
5-
pall, pallNA, pallv, pany, panyNA, panyv, pcount, pcountNA, pfirst, plast, pmean, pprod, psum, setlevels, topn, uniqLen, vswitch, psort,
4+
charToFact, count, countNA, countOccur, fduplicated, fpmin, fpmax, fpos, funique, iif, nif, nswitch,
5+
pall, pallNA, pallv, pany, panyNA, panyv, pcount, pcountNA, pfirst, plast, pmean, pprod, prange, psum, setlevels, topn, uniqLen, vswitch, psort,
66
getData, shareData, clearData
77
)

R/call.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@ panyv = function(..., value) as.logical(pcount(..., value = value))
1919
pcountNA = function(...) .Call(CpcountNAR, if (...length() == 1L && is.list(..1)) ..1 else list(...))
2020
pfirst = function(...) .Call(CpfirstR, FALSE, if (...length() == 1L && is.list(..1)) ..1 else list(...))
2121
plast = function(...) .Call(CpfirstR, TRUE, if (...length() == 1L && is.list(..1)) ..1 else list(...))
22+
fpmin = function(..., na.rm=FALSE) .Call(CfpminR, na.rm, if (...length() == 1L && is.list(..1)) ..1 else list(...))
23+
fpmax = function(..., na.rm=FALSE) .Call(CfpmaxR, na.rm, if (...length() == 1L && is.list(..1)) ..1 else list(...))
2224
pmean = function(..., na.rm=FALSE) .Call(CpmeanR, na.rm, if (...length() == 1L && is.list(..1)) ..1 else list(...))
2325
pprod = function(..., na.rm=FALSE) .Call(CpprodR, na.rm, if (...length() == 1L && is.list(..1)) ..1 else list(...))
26+
prange = function(..., na.rm=FALSE) .Call(CprangeR, na.rm, if (...length() == 1L && is.list(..1)) ..1 else list(...))
2427
psum = function(..., na.rm=FALSE) .Call(CpsumR, na.rm, if (...length() == 1L && is.list(..1)) ..1 else list(...))
2528
setlevels = function(x, old = levels(x), new, skip_absent=FALSE) invisible(.Call(CsetlevelsR, x, old, new, skip_absent))
2629
topn = function(vec, n=6L, decreasing=TRUE, hasna=TRUE,index=TRUE) if(index) .Call(CtopnR, vec, n, decreasing, hasna, parent.frame()) else vec[.Call(CtopnR, vec, n, decreasing, hasna, parent.frame())]

src/init.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@ static const R_CallMethodDef CallEntries[] = {
1818
{"CpcountR", (DL_FUNC) &pcountR, -1},
1919
{"CpcountNAR", (DL_FUNC) &pcountNAR, -1},
2020
{"CpfirstR", (DL_FUNC) &pfirstR, -1},
21+
{"CfpminR", (DL_FUNC) &fpminR, -1},
22+
{"CfpmaxR", (DL_FUNC) &fpmaxR, -1},
2123
{"CpmeanR", (DL_FUNC) &pmeanR, -1},
2224
{"CpprodR", (DL_FUNC) &pprodR, -1},
25+
{"CprangeR", (DL_FUNC) &prangeR, -1},
2326
{"CpsumR", (DL_FUNC) &psumR, -1},
2427
{"CsetlevelsR", (DL_FUNC) &setlevelsR, -1},
2528
{"CtopnR", (DL_FUNC) &topnR, -1},
@@ -50,7 +53,10 @@ void R_init_kit(DllInfo *dll) {
5053
R_RegisterCCallable("kit", "CpcountNAR", (DL_FUNC) &pcountNAR);
5154
R_RegisterCCallable("kit", "CpfirstR", (DL_FUNC) &pfirstR);
5255
R_RegisterCCallable("kit", "CpmeanR", (DL_FUNC) &pmeanR);
56+
R_RegisterCCallable("kit", "CfpminR", (DL_FUNC) &fpminR);
57+
R_RegisterCCallable("kit", "CfpmaxR", (DL_FUNC) &fpmaxR);
5358
R_RegisterCCallable("kit", "CpprodR", (DL_FUNC) &pprodR);
59+
R_RegisterCCallable("kit", "CprangeR", (DL_FUNC) &prangeR);
5460
R_RegisterCCallable("kit", "CpsumR", (DL_FUNC) &psumR);
5561
R_RegisterCCallable("kit", "CsetlevelsR", (DL_FUNC) &setlevelsR);
5662
R_RegisterCCallable("kit", "CtopnR", (DL_FUNC) &topnR);

src/kit.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,11 @@ extern SEXP panyR(SEXP na, SEXP args);
101101
extern SEXP pcountR(SEXP x, SEXP args);
102102
extern SEXP pcountNAR(SEXP args);
103103
extern SEXP pfirstR(SEXP last, SEXP args);
104+
extern SEXP fpminR(SEXP na, SEXP args);
105+
extern SEXP fpmaxR(SEXP na, SEXP args);
104106
extern SEXP pmeanR(SEXP na, SEXP args);
105107
extern SEXP pprodR(SEXP na, SEXP args);
108+
extern SEXP prangeR(SEXP na, SEXP args);
106109
extern SEXP psumR(SEXP na, SEXP args);
107110
extern SEXP setlevelsR(SEXP x, SEXP old_lvl, SEXP new_lvl, SEXP skip_absent);
108111
extern SEXP subSetColDataFrame(SEXP df, SEXP str);

0 commit comments

Comments
 (0)