Skip to content

Commit 0333c57

Browse files
committed
Fix+Feat
1 parent 4354338 commit 0333c57

File tree

7 files changed

+57
-24
lines changed

7 files changed

+57
-24
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: kit
22
Type: Package
33
Title: Data Manipulation Functions Implemented in C
4-
Version: 0.0.9
4+
Version: 0.0.10
55
Date: 2021-09-12
66
Authors@R: c(person("Morgan", "Jacob", role = c("aut", "cre", "cph"), email = "[email protected]"))
77
Author: Morgan Jacob [aut, cre, cph]

MD5

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
6071edd604dbeb75308cfbedc7790398 *cleanup
22
66d4daddd0163539f19e2cb783fc3bb9 *configure
3-
032f497563062c67c360f2cbbabad526 *DESCRIPTION
4-
5c267ba48bdd845348c286ec3b08f5c1 *inst/NEWS.Rd
3+
8ff1b02f18a64c7d6b963beddf1191cf *DESCRIPTION
4+
214838f2ee26d214e4f364864f7bed44 *inst/NEWS.Rd
55
a87b0f223435ed35607e8514562b8bfe *LICENSE
66
6375b9e30533e0495b98f4b5b829706b *man/charToFact.Rd
77
8f19a2c9feb2f352580fd4892650f285 *man/count.Rd
@@ -16,7 +16,7 @@ a137f7855b41b074e2babaf8a1562551 *man/shareData.Rd
1616
54f91d543a10f8c9aef7082da2b86de7 *man/topn.Rd
1717
3c628c2a27764ec5df2b4980921c310f *man/vswitch.Rd
1818
640100c58f36cf06c14aacd7ff7a946a *NAMESPACE
19-
a93eb67d15da2c12dde6b9a6de93e10b *R/call.R
19+
7d7d1d54ca3f9f17e4141de6c2b1ce34 *R/call.R
2020
34ba4d931a5bd0ba120ddef7e5327313 *README.md
2121
4826023c3ffe528db5e2af5db2a84b5a *src/dup.c
2222
e86a1960c335e7d534a4683b52d8b70c *src/dupLen.c
@@ -30,8 +30,8 @@ a52426250b954a335b1121948e057ee7 *src/Makevars.in
3030
ab9528d1b24d71ed2080743331b8a012 *src/psort.c
3131
44018b12fca6cccaabcd0f10deb421e4 *src/psum.c
3232
bafdafd654269acd054525571dbe1b44 *src/share.c
33-
e998e820fea6aa677e78a8cb1f7ba74c *src/topn.c
33+
53711690f6c15f3f36edb4b9360043a4 *src/topn.c
3434
c0f3fe6fca4e8492277a0d5f87528ce5 *src/utils.c
3535
3476a1e2381bb86f68a72844ee61bc7b *src/vswitch.c
36-
010429797d86eda96db95a459823d629 *tests/test_kit.R
37-
cb2f4f0290154a7a8525b3bfb3a812e3 *tests/test_kit.Rout.save
36+
336bd08ef00d953278cf64a00a000ac9 *tests/test_kit.R
37+
f871740ade1b3172748d7b1f63586098 *tests/test_kit.Rout.save

R/call.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@ funique = function(x, fromLast = FALSE) .Call(CdupR, x, TRUE, fromLast)
99
iif = function(test, yes, no, na=NULL, tprom=FALSE, nThread=getOption("kit.nThread")) .Call(CiifR, test, yes, no, na, tprom, nThread)
1010
nif = function(..., default=NULL) .Call(CnifR, default, parent.frame(), as.list(substitute(...())))
1111
nswitch = function(x, ..., default=NULL, nThread=getOption("kit.nThread"), checkEnc = TRUE) .Call(CnswitchR, x, default, nThread, checkEnc, list(...))
12-
pall = function(..., na.rm=FALSE) .Call(CpallR, na.rm, if (length(a <- list(...)) == 1 && is.data.frame(a[[1]])) a[[1]] else a)
13-
pany = function(..., na.rm=FALSE) .Call(CpanyR, na.rm, if (length(a <- list(...)) == 1 && is.data.frame(a[[1]])) a[[1]] else a)
12+
pall = function(..., na.rm=FALSE) .Call(CpallR, na.rm, if (...length() == 1L && is.list(..1)) ..1 else list(...))
13+
pany = function(..., na.rm=FALSE) .Call(CpanyR, na.rm, if (...length() == 1L && is.list(..1)) ..1 else list(...))
1414
pcount = function(..., value) .Call(CpcountR, value, list(...))
15-
pmean = function(..., na.rm=FALSE) .Call(CpmeanR, na.rm, if (length(a <- list(...)) == 1 && is.data.frame(a[[1]])) a[[1]] else a)
16-
pprod = function(..., na.rm=FALSE) .Call(CpprodR, na.rm, if (length(a <- list(...)) == 1 && is.data.frame(a[[1]])) a[[1]] else a)
17-
psum = function(..., na.rm=FALSE) .Call(CpsumR, na.rm, if (length(a <- list(...)) == 1 && is.data.frame(a[[1]])) a[[1]] else a)
15+
pmean = function(..., na.rm=FALSE) .Call(CpmeanR, na.rm, if (...length() == 1L && is.list(..1)) ..1 else list(...))
16+
pprod = function(..., na.rm=FALSE) .Call(CpprodR, na.rm, if (...length() == 1L && is.list(..1)) ..1 else list(...))
17+
psum = function(..., na.rm=FALSE) .Call(CpsumR, na.rm, if (...length() == 1L && is.list(..1)) ..1 else list(...))
1818
setlevels = function(x, old = levels(x), new, skip_absent=FALSE) invisible(.Call(CsetlevelsR, x, old, new, skip_absent))
1919
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())]
2020
uniqLen = function(x) .Call(CdupLenR, x)
2121
vswitch = function(x, values, outputs, default=NULL, nThread=getOption("kit.nThread"), checkEnc = TRUE) .Call(CvswitchR, x, values, outputs, default, nThread, checkEnc)
2222

23-
.onAttach = function(libname, pkgname) packageStartupMessage(paste0("Attaching kit 0.0.9 (OPENMP ",if(.Call(CompEnabledR)) "enabled" else "disabled"," using 1 thread)"))
23+
.onAttach = function(libname, pkgname) packageStartupMessage(paste0("Attaching kit 0.0.10 (OPENMP ",if(.Call(CompEnabledR)) "enabled" else "disabled"," using 1 thread)"))
2424
.onLoad = function(libname, pkgname) options("kit.nThread"=1L) #nocov
2525
.onUnload = function(libpath) library.dynam.unload("kit", libpath) #nocov
2626

inst/NEWS.Rd

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,19 @@
44

55
\newcommand{\CRANpkg}{\href{https://CRAN.R-project.org/package=#1}{\pkg{#1}}}
66

7+
\section{version 0.0.10 (2021-09-25)}{
8+
\subsection{New Features}{
9+
\itemize{
10+
\item Function \code{\strong{psum}}, \code{\strong{pmean}}, \code{\strong{pprod}}, \code{\strong{pany}} and \code{\strong{pall}} now support lists. Thanks to Sebastian Krantz for the request and code suggestion.
11+
}
12+
}
13+
\subsection{Bug Fixes}{
14+
\itemize{
15+
\item Function \code{\strong{topn}} should now work for ALTREP object. Thanks to @ben-schwen for raising an issue.
16+
}
17+
}
18+
}
19+
720
\section{version 0.0.9 (2021-09-12)}{
821
\subsection{Notes}{
922
\itemize{

src/topn.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,17 @@ SEXP topnR(SEXP vec, SEXP n, SEXP dec, SEXP hasna, SEXP env) {
4141
const SEXPTYPE tvec = UTYPEOF(vec);
4242
const Rboolean vhasna = asLogical(hasna);
4343
if ( ((len0 > 2000 && vhasna == FALSE) || (len0 > 1500 && vhasna == TRUE)) && (tvec == INTSXP || tvec == REALSXP)) {
44-
SEXP ans = PROTECT(callToOrder(vec, "radix", dcr, TRUE, env));
45-
SETLENGTH(ans, len0);
46-
UNPROTECT(1);
44+
SEXP prem = PROTECT(callToOrder(vec, "radix", dcr, TRUE, env));
45+
SEXP ans = PROTECT(allocVector(UTYPEOF(prem), len0));
46+
switch(UTYPEOF(prem)) {
47+
case INTSXP: {
48+
memcpy(INTEGER(ans), INTEGER(prem), len0 *sizeof(int));
49+
} break;
50+
case REALSXP: {
51+
memcpy(REAL(ans), REAL(prem), len0 *sizeof(double));
52+
} break;
53+
}
54+
UNPROTECT(2);
4755
return ans;
4856
}
4957
SEXP ans = PROTECT(allocVector(INTSXP, len0));

tests/test_kit.R

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ x5 = sample(c(1:1000),3e3,TRUE)
7373
x6 = sample(as.numeric(c(1:1000)),1e3,TRUE)
7474
class2134 = setClass("class2134", slots=list(x="numeric"))
7575
s1 = class2134(x=20191231)
76+
x7 = seq.int(1e4)
7677

7778
check("0001.001", topn(x0, 1L, decreasing=FALSE), order(x0)[1:1])
7879
check("0001.002", topn(x0, 2L, decreasing=FALSE), order(x0)[1:2])
@@ -202,8 +203,10 @@ check("0001.126", topn(x4, 2L, decreasing = TRUE,hasna = FALSE), error = "Type r
202203
check("0001.127", topn(x4, 2L, decreasing=FALSE,hasna = FALSE), error = "Type raw is not supported.")
203204
check("0001.128", topn(c(1,2,4,10,2,3), 2L, hasna=c(FALSE,TRUE)), error = "Argument 'hasna' must be TRUE or FALSE and length 1.")
204205
check("0001.129", topn(x5, 2001L,decreasing = FALSE), order(x5, decreasing=FALSE)[1:2001])
206+
check("0001.130", topn(x7,1e4,decreasing=FALSE), order(x7, decreasing=FALSE))
207+
check("0001.131", topn(as.numeric(x7),1e4,decreasing=FALSE), order(as.numeric(x7), decreasing=FALSE))
205208

206-
rm(s1, class2134, x0, x1, x2, x3, x4, x5, x6)
209+
rm(s1, class2134, x0, x1, x2, x3, x4, x5, x6, x7)
207210

208211
# --------------------------------------------------------------------------------------------------
209212
# iif
@@ -703,6 +706,7 @@ check("0005.025", psum(NA_complex_, na.rm = TRUE), 0+0i)
703706
check("0005.026", psum(iris[,1:2]), rowSums(iris[,1:2]))
704707
check("0005.027", psum(iris[,1:2],iris[,1:2]), error = "Argument 1 is of type list. Only integer, double and complex types are supported.Data.frame (of the previous types) is also supported as a single input.")
705708
check("0005.028", psum(1:150,iris$Species, na.rm = FALSE), error="Function 'psum' is not meaningful for factors.")
709+
check("0005.029", psum(unclass(mtcars)),psum(mtcars))
706710

707711
# --------------------------------------------------------------------------------------------------
708712
# pprod
@@ -735,7 +739,8 @@ check("0006.024", pprod(NA_real_, na.rm = TRUE), 1)
735739
check("0006.025", pprod(NA_complex_, na.rm = TRUE), 1+0i)
736740
check("0006.026", pprod(iris[,1:2]), iris$Sepal.Length*iris$Sepal.Width)
737741
check("0006.027", pprod(iris[,1:2],iris[,1:2]), error = "Argument 1 is of type list. Only integer, double and complex types are supported.Data.frame (of the previous types) is also supported as a single input.")
738-
check("0005.028", pprod(1:150,iris$Species, na.rm = FALSE), error="Function 'pprod' is not meaningful for factors.")
742+
check("0006.028", pprod(1:150,iris$Species, na.rm = FALSE), error="Function 'pprod' is not meaningful for factors.")
743+
check("0006.029", pprod(unclass(mtcars)),pprod(mtcars))
739744

740745
rm(x, y, z, x0, y0, z0)
741746

@@ -1113,7 +1118,8 @@ check("0011.022", pmean(x1, y1, z1, na.rm = TRUE), sapply(1:100, function(i) mea
11131118
check("0011.023", pmean(NA_integer_, na.rm = TRUE), mean(NA_integer_,na.rm = TRUE))
11141119
check("0011.024", pmean(NA_real_, na.rm = TRUE), mean(NA_real_,na.rm = TRUE))
11151120
check("0011.025", pmean(data.frame(x,y,z), na.rm = TRUE), pmean(x,y,z,na.rm = TRUE))
1116-
check("0005.026", pmean(1:150,iris$Species, na.rm = FALSE), error="Function 'pmean' is not meaningful for factors.")
1121+
check("0011.026", pmean(1:150,iris$Species, na.rm = FALSE), error="Function 'pmean' is not meaningful for factors.")
1122+
check("0011.027", pmean(unclass(mtcars)),pmean(mtcars))
11171123

11181124
rm(x, y, z, x0, y0, z0, x1, y1, z1)
11191125

tests/test_kit.Rout.save

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Type 'q()' to quit R.
5353
+ }
5454
>
5555
> library(kit); unloadNamespace("kit")
56-
Attaching kit 0.0.9 (OPENMP enabled using 1 thread)
56+
Attaching kit 0.0.10 (OPENMP enabled using 1 thread)
5757
>
5858
> topn = kit::topn
5959
> setlevels = kit::setlevels
@@ -93,6 +93,7 @@ Attaching kit 0.0.9 (OPENMP enabled using 1 thread)
9393
> x6 = sample(as.numeric(c(1:1000)),1e3,TRUE)
9494
> class2134 = setClass("class2134", slots=list(x="numeric"))
9595
> s1 = class2134(x=20191231)
96+
> x7 = seq.int(1e4)
9697
>
9798
> check("0001.001", topn(x0, 1L, decreasing=FALSE), order(x0)[1:1])
9899
> check("0001.002", topn(x0, 2L, decreasing=FALSE), order(x0)[1:2])
@@ -222,8 +223,10 @@ Attaching kit 0.0.9 (OPENMP enabled using 1 thread)
222223
> check("0001.127", topn(x4, 2L, decreasing=FALSE,hasna = FALSE), error = "Type raw is not supported.")
223224
> check("0001.128", topn(c(1,2,4,10,2,3), 2L, hasna=c(FALSE,TRUE)), error = "Argument 'hasna' must be TRUE or FALSE and length 1.")
224225
> check("0001.129", topn(x5, 2001L,decreasing = FALSE), order(x5, decreasing=FALSE)[1:2001])
226+
> check("0001.130", topn(x7,1e4,decreasing=FALSE), order(x7, decreasing=FALSE))
227+
> check("0001.131", topn(as.numeric(x7),1e4,decreasing=FALSE), order(as.numeric(x7), decreasing=FALSE))
225228
>
226-
> rm(s1, class2134, x0, x1, x2, x3, x4, x5, x6)
229+
> rm(s1, class2134, x0, x1, x2, x3, x4, x5, x6, x7)
227230
>
228231
> # --------------------------------------------------------------------------------------------------
229232
> # iif
@@ -723,6 +726,7 @@ Attaching kit 0.0.9 (OPENMP enabled using 1 thread)
723726
> check("0005.026", psum(iris[,1:2]), rowSums(iris[,1:2]))
724727
> check("0005.027", psum(iris[,1:2],iris[,1:2]), error = "Argument 1 is of type list. Only integer, double and complex types are supported.Data.frame (of the previous types) is also supported as a single input.")
725728
> check("0005.028", psum(1:150,iris$Species, na.rm = FALSE), error="Function 'psum' is not meaningful for factors.")
729+
> check("0005.029", psum(unclass(mtcars)),psum(mtcars))
726730
>
727731
> # --------------------------------------------------------------------------------------------------
728732
> # pprod
@@ -755,7 +759,8 @@ Attaching kit 0.0.9 (OPENMP enabled using 1 thread)
755759
> check("0006.025", pprod(NA_complex_, na.rm = TRUE), 1+0i)
756760
> check("0006.026", pprod(iris[,1:2]), iris$Sepal.Length*iris$Sepal.Width)
757761
> check("0006.027", pprod(iris[,1:2],iris[,1:2]), error = "Argument 1 is of type list. Only integer, double and complex types are supported.Data.frame (of the previous types) is also supported as a single input.")
758-
> check("0005.028", pprod(1:150,iris$Species, na.rm = FALSE), error="Function 'pprod' is not meaningful for factors.")
762+
> check("0006.028", pprod(1:150,iris$Species, na.rm = FALSE), error="Function 'pprod' is not meaningful for factors.")
763+
> check("0006.029", pprod(unclass(mtcars)),pprod(mtcars))
759764
>
760765
> rm(x, y, z, x0, y0, z0)
761766
>
@@ -1133,7 +1138,8 @@ Attaching kit 0.0.9 (OPENMP enabled using 1 thread)
11331138
> check("0011.023", pmean(NA_integer_, na.rm = TRUE), mean(NA_integer_,na.rm = TRUE))
11341139
> check("0011.024", pmean(NA_real_, na.rm = TRUE), mean(NA_real_,na.rm = TRUE))
11351140
> check("0011.025", pmean(data.frame(x,y,z), na.rm = TRUE), pmean(x,y,z,na.rm = TRUE))
1136-
> check("0005.026", pmean(1:150,iris$Species, na.rm = FALSE), error="Function 'pmean' is not meaningful for factors.")
1141+
> check("0011.026", pmean(1:150,iris$Species, na.rm = FALSE), error="Function 'pmean' is not meaningful for factors.")
1142+
> check("0011.027", pmean(unclass(mtcars)),pmean(mtcars))
11371143
>
11381144
> rm(x, y, z, x0, y0, z0, x1, y1, z1)
11391145
>
@@ -1696,4 +1702,4 @@ Attaching kit 0.0.9 (OPENMP enabled using 1 thread)
16961702
>
16971703
> proc.time()
16981704
user system elapsed
1699-
4.169 0.504 4.671
1705+
4.251 0.614 4.957

0 commit comments

Comments
 (0)