Skip to content

Commit b4dd554

Browse files
authored
Merge pull request #48 from fastverse/development
Development
2 parents 99413b6 + c82e5cd commit b4dd554

File tree

4 files changed

+23
-19
lines changed

4 files changed

+23
-19
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Authors@R: c(person("Morgan", "Jacob", role = c("aut", "cre", "cph"), email = "m
88
Author: Morgan Jacob [aut, cre, cph], Sebastian Krantz [ctb]
99
Maintainer: Morgan Jacob <[email protected]>
1010
Description: Basic functions, implemented in C, for large data manipulation. Fast vectorised ifelse()/nested if()/switch() functions, psum()/pprod() functions equivalent to pmin()/pmax() plus others which are missing from base R. Most of these functions are callable at C level.
11-
URL: https://fastverse.github.io/kit/, https://github.com/fastverse/kit
11+
URL: https://fastverse.org/kit/, https://github.com/fastverse/kit
1212
License: GPL-3
1313
Depends: R (>= 3.1.0)
1414
Suggests: knitr, rmarkdown

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ install.packages("kit", repos = "https://fastverse.r-universe.dev")
2626

2727
Vector-valued functions operating in parallel over vectors or data frames:
2828

29-
- **`psum`, `pprod`, `pmean`**: Parallel sum, product, and mean (similar to `pmin`/`pmax`)
29+
- **`psum`, `pprod`, `pmean`**: Parallel sum, product, and mean
30+
- **`fpmin`, `fpmax`, `prange`**: Parallel minimum, maximum, and range (complements base `pmin`/`pmax` with `na.rm` support)
3031
- **`pall`, `pany`**: Parallel all/any operations
3132
- **`pcount`, `pcountNA`**: Count occurrences of values or NAs
3233
- **`pfirst`, `plast`**: First/last non-missing values
@@ -36,6 +37,9 @@ x <- c(1, 3, NA, 5)
3637
y <- c(2, NA, 4, 1)
3738
psum(x, y, na.rm = TRUE) # [1] 3 3 4 6
3839
pmean(x, y, na.rm = TRUE) # [1] 1.5 3.0 4.0 3.0
40+
fpmin(x, y, na.rm = TRUE) # [1] 1 3 4 1
41+
fpmax(x, y, na.rm = TRUE) # [1] 2 3 4 5
42+
prange(x, y, na.rm = TRUE) # [1] 1 0 0 4
3943
```
4044

4145
### Vectorized and Nested Switches
@@ -83,7 +87,7 @@ uniqLen(iris$Species) # Faster than length(unique())
8387

8488
## Documentation
8589

86-
Full documentation available at: https://fastverse.github.io/kit/
90+
Full documentation available at: https://fastverse.org/kit/
8791

8892
## License
8993

_pkgdown.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
url: https://fastverse.github.io/kit/
1+
url: https://fastverse.org/kit/
22

33
home:
44
title: Data Manipulation Functions Implemented in C

src/psum.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,7 +1081,7 @@ SEXP fpminR(SEXP na, SEXP args) {
10811081
if (init_convert) {
10821082
const int *restrict p0 = (type0 == LGLSXP) ? LOGICAL(args0) : INTEGER(args0);
10831083
for (ssize_t j = 0; j < len0; ++j) {
1084-
pans[j] = p0[j] == NA_INTEGER ? R_NaN : (double)p0[j];
1084+
pans[j] = p0[j] == NA_INTEGER ? NA_REAL : (double)p0[j];
10851085
}
10861086
}
10871087
if(narm) {
@@ -1120,7 +1120,7 @@ SEXP fpminR(SEXP na, SEXP args) {
11201120
}
11211121
for (ssize_t j = 0; j < len0; ++j) {
11221122
if (!found[j]) {
1123-
pans[j] = R_NaN; // All values were NA
1123+
pans[j] = NA_REAL; // All values were NA
11241124
}
11251125
}
11261126
} else {
@@ -1130,7 +1130,7 @@ SEXP fpminR(SEXP na, SEXP args) {
11301130
const double *restrict pa = REAL(argi);
11311131
for (ssize_t j = 0; j < len0; ++j) {
11321132
if (ISNAN(pans[j]) || ISNAN(pa[j])) {
1133-
pans[j] = R_NaN;
1133+
pans[j] = NA_REAL;
11341134
} else if (pa[j] < pans[j]) {
11351135
pans[j] = pa[j];
11361136
}
@@ -1139,7 +1139,7 @@ SEXP fpminR(SEXP na, SEXP args) {
11391139
const int *restrict pa = (UTYPEOF(argi) == LGLSXP) ? LOGICAL(argi) : INTEGER(argi);
11401140
for (ssize_t j = 0; j < len0; ++j) {
11411141
if (ISNAN(pans[j]) || pa[j] == NA_INTEGER) {
1142-
pans[j] = R_NaN;
1142+
pans[j] = NA_REAL;
11431143
} else if ((double)pa[j] < pans[j]) {
11441144
pans[j] = (double)pa[j];
11451145
}
@@ -1250,7 +1250,7 @@ SEXP fpmaxR(SEXP na, SEXP args) {
12501250
if (init_convert) {
12511251
const int *restrict p0 = (type0 == LGLSXP) ? LOGICAL(args0) : INTEGER(args0);
12521252
for (ssize_t j = 0; j < len0; ++j) {
1253-
pans[j] = p0[j] == NA_INTEGER ? R_NaN : (double)p0[j];
1253+
pans[j] = p0[j] == NA_INTEGER ? NA_REAL : (double)p0[j];
12541254
}
12551255
}
12561256
if(narm) {
@@ -1289,7 +1289,7 @@ SEXP fpmaxR(SEXP na, SEXP args) {
12891289
}
12901290
for (ssize_t j = 0; j < len0; ++j) {
12911291
if (!found[j]) {
1292-
pans[j] = R_NaN; // All values were NA
1292+
pans[j] = NA_REAL; // All values were NA
12931293
}
12941294
}
12951295
} else {
@@ -1299,7 +1299,7 @@ SEXP fpmaxR(SEXP na, SEXP args) {
12991299
const double *restrict pa = REAL(argi);
13001300
for (ssize_t j = 0; j < len0; ++j) {
13011301
if (ISNAN(pans[j]) || ISNAN(pa[j])) {
1302-
pans[j] = R_NaN;
1302+
pans[j] = NA_REAL;
13031303
} else if (pa[j] > pans[j]) {
13041304
pans[j] = pa[j];
13051305
}
@@ -1308,7 +1308,7 @@ SEXP fpmaxR(SEXP na, SEXP args) {
13081308
const int *restrict pa = (UTYPEOF(argi) == LGLSXP) ? LOGICAL(argi) : INTEGER(argi);
13091309
for (ssize_t j = 0; j < len0; ++j) {
13101310
if (ISNAN(pans[j]) || pa[j] == NA_INTEGER) {
1311-
pans[j] = R_NaN;
1311+
pans[j] = NA_REAL;
13121312
} else if ((double)pa[j] > pans[j]) {
13131313
pans[j] = (double)pa[j];
13141314
}
@@ -1370,7 +1370,7 @@ SEXP prangeR(SEXP na, SEXP args) {
13701370
if (type0 != REALSXP) {
13711371
const int *restrict p0 = (type0 == LGLSXP) ? LOGICAL(args0) : INTEGER(args0);
13721372
for (ssize_t j = 0; j < len0; ++j) {
1373-
pans[j] = p0[j] == NA_INTEGER ? R_NaN : (double)p0[j];
1373+
pans[j] = p0[j] == NA_INTEGER ? NA_REAL : (double)p0[j];
13741374
}
13751375
} else {
13761376
const double *restrict p0 = REAL(args0);
@@ -1432,7 +1432,7 @@ SEXP prangeR(SEXP na, SEXP args) {
14321432
}
14331433
for (ssize_t j = 0; j < len0; ++j) {
14341434
if (!found[j]) {
1435-
pans[j] = R_NaN;
1435+
pans[j] = NA_REAL;
14361436
} else {
14371437
pans[j] = pmax[j] - pans[j];
14381438
}
@@ -1447,8 +1447,8 @@ SEXP prangeR(SEXP na, SEXP args) {
14471447
const double *restrict pa = REAL(argi);
14481448
for (ssize_t j = 0; j < len0; ++j) {
14491449
if (ISNAN(pans[j]) || ISNAN(pa[j])) {
1450-
pans[j] = R_NaN;
1451-
pmax[j] = R_NaN;
1450+
pans[j] = NA_REAL;
1451+
pmax[j] = NA_REAL;
14521452
} else {
14531453
if (pa[j] < pans[j]) {
14541454
pans[j] = pa[j];
@@ -1462,8 +1462,8 @@ SEXP prangeR(SEXP na, SEXP args) {
14621462
const int *restrict pa = (UTYPEOF(argi) == LGLSXP) ? LOGICAL(argi) : INTEGER(argi);
14631463
for (ssize_t j = 0; j < len0; ++j) {
14641464
if (ISNAN(pans[j]) || pa[j] == NA_INTEGER) {
1465-
pans[j] = R_NaN;
1466-
pmax[j] = R_NaN;
1465+
pans[j] = NA_REAL;
1466+
pmax[j] = NA_REAL;
14671467
} else {
14681468
const double v = (double)pa[j];
14691469
if (v < pans[j]) {
@@ -1478,7 +1478,7 @@ SEXP prangeR(SEXP na, SEXP args) {
14781478
}
14791479
for (ssize_t j = 0; j < len0; ++j) {
14801480
if (ISNAN(pans[j]) || ISNAN(pmax[j])) {
1481-
pans[j] = R_NaN;
1481+
pans[j] = NA_REAL;
14821482
} else {
14831483
pans[j] = pmax[j] - pans[j];
14841484
}

0 commit comments

Comments
 (0)