Skip to content

Commit ce04a93

Browse files
committed
updated documentation, fixed create.sub.objects() and datsteps()
1 parent ecfa3f9 commit ce04a93

8 files changed

Lines changed: 80 additions & 19 deletions

File tree

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ Description: Converting date ranges into dating 'steps' eases the visualization
88
License: CC BY-SA 4.0
99
Encoding: UTF-8
1010
LazyData: true
11-
RoxygenNote: 6.0.1
11+
RoxygenNote: 7.0.2

NAMESPACE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# Generated by roxygen2: do not edit by hand
22

3+
export(create.sub.objects)
34
export(datsteps)
5+
export(get.weights)
46
export(scaleweight)

R/datplot_funs.R

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,19 @@
1212
#'
1313
#' @export datsteps
1414

15-
datsteps <- function(df, stepsize = 5) {
15+
datsteps <- function(df, stepsize = "auto") {
16+
if (stepsize == "auto") {
17+
timespans <- abs(df[,3] - df[,4])
18+
if (min(timespans) < 1) {
19+
stepsize <- 1
20+
} else {
21+
stepsize <- min(timespans)
22+
}
23+
print(paste("Using stepsize = ", stepsize, ". (auto)", sep = ""))
24+
} else if (!is.numeric(stepsize)) {
25+
print("Error: stepsize has to be numeric.")
26+
stop()
27+
}
1628
result <- as.data.frame(NULL)
1729
if (any(df[,3] > df[,4]) == TRUE) {
1830
print(paste("Error: Dating seems to be in wrong order at ",
@@ -36,7 +48,6 @@ datsteps <- function(df, stepsize = 5) {
3648
return(result)
3749
}
3850

39-
4051
#' Calculate the weights for each dated object
4152
#'
4253
#' Requires a dataframe with 4 variables: ID (ideally factor), group (ideally factor),
@@ -78,15 +89,18 @@ get.weights <- function(DAT_min, DAT_max) {
7889
#'
7990
#' @export create.sub.objects
8091

81-
# this could be optimizes, maybe with apply()? because it takes too long
8292
create.sub.objects <- function(df, stepsize) {
8393

8494
mean_year_index <- which(df[,4]-df[,3] < stepsize)
8595

86-
outputnr <- ceiling(sum(((abs(df[-mean_year_index,3]-df[-mean_year_index,4]))/stepsize)+1))
87-
outputnr <- outputnr+length(mean_year_index)
96+
if (length(mean_year_index) == 0) {
97+
outputnr <- ceiling(sum(((abs(df[,3]-df[,4]))/stepsize)+1))
98+
} else {
99+
outputnr <- ceiling(sum(((abs(df[-mean_year_index,3]-df[-mean_year_index,4]))/stepsize)+1))
100+
outputnr <- outputnr+length(mean_year_index)
101+
}
88102

89-
result <- as.data.frame(matrix(ncol = ncol(df)+1, nrow = outputnr))
103+
result <- as.data.frame(matrix(ncol = ncol(df)+1, nrow = outputnr+100))
90104

91105
colnames(result) <- c(colnames(df), "DAT_step")
92106
for (i in 1:nrow(df)) {

datplot.Rproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ StripTrailingWhitespace: Yes
1818
BuildType: Package
1919
PackageUseDevtools: Yes
2020
PackageInstallArgs: --no-multiarch --with-keep.source
21+
PackageRoxygenize: rd,collate,namespace

man/create.sub.objects.Rd

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/datsteps.Rd

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/get.weights.Rd

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/scaleweight.Rd

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)