Skip to content

Commit 1c6444d

Browse files
authored
Merge pull request #12 from KWB-R/dev
Release 0.5.1 (bug fix and minor change)
2 parents 2a50458 + 6699ff6 commit 1c6444d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+271
-120
lines changed

DESCRIPTION

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: kwb.utils
22
Title: General Utility Functions Developed at KWB
3-
Version: 0.5.0
3+
Version: 0.5.1
44
Authors@R:
55
c(person(given = "Hauke",
66
family = "Sonnenberg",
@@ -29,4 +29,4 @@ Suggests:
2929
VignetteBuilder:
3030
knitr
3131
Encoding: UTF-8
32-
RoxygenNote: 6.1.1
32+
RoxygenNote: 7.1.0

NEWS.md

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# Current
2+
3+
# [kwb.utils 0.5.1](https://github.com/KWB-R/kwb.utils/releases/tag/v0.5.1) <small>2020-04-20</small>
4+
5+
* Fix bug in moveColumnsToFront(): keep data frame structure in case that the
6+
data frame has only one column
7+
* createMatrix(): Set defaults for name.row and name.col to NULL (was: "")
8+
19
# [kwb.utils 0.5.0](https://github.com/KWB-R/kwb.utils/releases/tag/v0.5.0) <small>2019-12-17</small>
210

311
* new: toPdf()

R/column.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ insertColumns <- function(
388388
#'
389389
moveColumnsToFront <- function(x, columns = NULL)
390390
{
391-
selectColumns(x, moveToFront(names(x), columns))
391+
selectColumns(x, moveToFront(names(x), columns), drop = FALSE)
392392
}
393393

394394
# pasteColumns -----------------------------------------------------------------

R/list.R

+9-12
Original file line numberDiff line numberDiff line change
@@ -273,19 +273,16 @@ selectElements <- function(x, elements = NULL, do.stop = TRUE, do.warn = TRUE)
273273

274274
L <- length(elements)
275275

276-
result <- if (L == 0) {
277-
278-
list()
279-
280-
} else if (L == 1) {
281-
282-
x[[elements]]
283-
284-
} else {
285-
286-
x[elements]
287-
}
276+
if (L == 0L) {
277+
return(list())
278+
}
288279

280+
if (L == 1L) {
281+
return(x[[elements]])
282+
}
283+
284+
result <- x[elements]
285+
289286
newNames <- names(elements)
290287

291288
if (! is.null(newNames)) {

R/matrix.R

+18-12
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ randomMatrix <- function(
9797
#' @param rowNames character vector of row names to be given to the matrix
9898
#' @param colNames character vector of column names to be given to the matrix
9999
#' @param value value to be given to each matrix element
100-
#' @param name.row name to be given to the row dimension (default: "")
101-
#' @param name.col name to be given to the column dimension (default: "")
100+
#' @param name.row optional. Name to be given to the row dimension
101+
#' @param name.col optional. Name to be given to the column dimension
102102
#' @return matrix with \code{rowNames} as row names and \code{colNames} as
103103
#' column names, filled with \emph{value} at each position
104104
#' @export
@@ -116,7 +116,7 @@ randomMatrix <- function(
116116
#' createMatrix(c("A", "B", "C"), name.row = "Letters")
117117
#'
118118
createMatrix <- function(
119-
rowNames, colNames = rowNames, value = 0, name.row = "", name.col = ""
119+
rowNames, colNames = rowNames, value = 0, name.row = NULL, name.col = NULL
120120
)
121121
{
122122
stopifnot(is.character(rowNames))
@@ -127,16 +127,14 @@ createMatrix <- function(
127127

128128
dimnames <- list(rowNames, colNames)
129129

130-
if (! is.null(name.row)) {
130+
if (! is.null(name.row) || ! is.null(name.col)) {
131131

132-
names(dimnames)[1] <- name.row
132+
names(dimnames) <- c(
133+
defaultIfNULL(name.row, ""),
134+
defaultIfNULL(name.col, "")
135+
)
133136
}
134-
135-
if (! is.null(name.col)) {
136-
137-
names(dimnames)[2] <- name.col
138-
}
139-
137+
140138
matrix(
141139
data = rep(value, times = nrows * length(colNames)),
142140
nrow = nrows,
@@ -274,7 +272,15 @@ diffrows <- function(x)
274272
{
275273
stopIfNotMatrix(x)
276274

277-
do.call(rbind, lapply(seq_len(nrow(x) - 1), function(i) x[i + 1, ] - x[i, ]))
275+
rows <- lapply(seq_len(nrow(x) - 1L), function(i) x[i + 1L, ] - x[i, ])
276+
277+
result <- do.call(rbind, rows)
278+
279+
if (ncol(result) == 1L) {
280+
colnames(result) <- colnames(x)
281+
}
282+
283+
result
278284
}
279285

280286
# asColumnList -----------------------------------------------------------------

man/assertRowsAndColumns.Rd

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

man/catAndRun.Rd

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

man/checkForMissingColumns.Rd

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

man/colStatistics.Rd

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

man/compareDataFrames.Rd

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

man/compareSets.Rd

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

man/convertCsvFile.Rd

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

man/copyDirectoryStructure.Rd

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

man/createMatrix.Rd

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

man/extractRowRanges.Rd

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

man/frequencyTable.Rd

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

man/getTagNames.Rd

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

man/hsDelEmptyCols.Rd

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

man/hsMatrixToListForm.Rd

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

man/hsOpenWindowsExplorer.Rd

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

0 commit comments

Comments
 (0)