1+ # ' checking if value is uniqe in set
2+ # ' @param x vector to check
3+ is_unique <- function (x ){
4+ ! is_duplicate(x )
5+ }
6+
7+ # ' checking if value is duplicated in set
8+ # ' @param x vector to check
9+ is_duplicate <- function (x ){
10+ x %in% x [duplicated(x )]
11+ }
12+
13+ # ' extract specific item from each list element
14+ # ' @param l list
15+ # ' @param item name or index of item to extract
16+ get_list_item <- function (l , item , unlist = TRUE ){
17+ tmp <- lapply(l , `[` , item )
18+ index <- vapply(tmp , is.null , TRUE )
19+ tmp [index ] <- NA
20+ if ( unlist ){
21+ return (unlist(tmp ))
22+ }else {
23+ return (tmp )
24+ }
25+ }
26+
27+
28+ # ' text function: wrapper for system.file() to access test files
29+ # ' @param x name of the file
30+ # ' @param pattern pattern of file name
31+ # ' @keywords internal
32+ test_file <- function (x = NULL , pattern = NULL , full.names = FALSE ){
33+ if (is.numeric(x )){
34+ return (dp_tf(dp_tf()[(x - 1 ) %% length(dp_tf()) + 1 ]))
35+ }
36+ if (is.null(x )){
37+ return (
38+ list.files(
39+ system.file(
40+ " testfiles" ,
41+ package = " diffrprojects"
42+ ),
43+ pattern = pattern ,
44+ full.names = full.names
45+ )
46+ )
47+ }else if (x == " " ){
48+ return (
49+ list.files(
50+ system.file(
51+ " testfiles" ,
52+ package = " diffrprojects"
53+ ),
54+ pattern = pattern ,
55+ full.names = full.names
56+ )
57+ )
58+ }else {
59+ return (
60+ system.file(
61+ paste(" testfiles" , x , sep = " /" ),
62+ package = " diffrprojects" )
63+ )
64+ }
65+ }
66+
67+
68+
69+
70+ # ' function rbinding list elements
71+ # ' @param l list
72+ # ' @keywords internal
73+ rbind_list <- function (l ){
74+ tmp <- do.call(rbind , l )
75+ rownames(tmp ) <- NULL
76+ as.data.frame(tmp , stringsAsFactors = FALSE )
77+ }
78+
179# ' function that shifts vector values to right or left
280# '
381# ' @param x Vector for which to shift values
886# ' @param default The value that should be inserted by default.
987# ' @param invert Whether or not the default shift directions
1088# ' should be inverted.
11- # ' @export
89+ # ' @keywords internal
1290shift <- function (x , n = 0 , default = NA , invert = FALSE ){
1391 n <-
1492 switch (
@@ -44,6 +122,7 @@ shift <- function(x, n=0, default=NA, invert=FALSE){
44122# ' @param x the values to be bound
45123# ' @param max upper boundary
46124# ' @param min lower boundary
125+ # ' @keywords internal
47126bind_between <- function (x , min , max ){
48127 x [x < min ] <- min
49128 x [x > max ] <- max
@@ -54,7 +133,7 @@ bind_between <- function(x, min, max){
54133# ' function for binding data.frames even if names do not match
55134# ' @param df1 first data.frame to rbind
56135# ' @param df2 second data.frame to rbind
57- # ' @export
136+ # ' @keywords internal
58137rbind_fill <- function (df1 = data.frame (), df2 = data.frame ()){
59138 names_df <- c(names(df1 ), names(df2 ))
60139 if ( dim1(df1 ) > 0 ){
@@ -74,10 +153,10 @@ rbind_fill <- function(df1=data.frame(), df2=data.frame()){
74153
75154
76155# ' function that checks is values are in between values
77- # ' @export
78156# ' @param x input vector
79157# ' @param y lower bound
80158# ' @param z upper bound
159+ # ' @keywords internal
81160is_between <- function (x ,y ,z ){
82161 return (x > = y & x < = z )
83162}
@@ -89,9 +168,7 @@ is_between <- function(x,y,z){
89168# ' @param length number of elements to be returned
90169# ' @param from first element to be returned
91170# ' @param to last element to be returned
92- # '
93- # ' @export
94- # '
171+ # ' @keywords internal
95172get_vector_element <-
96173 function (vec , length = 100 , from = NULL , to = NULL ){
97174 # helper functions
@@ -151,23 +228,23 @@ get_vector_element <-
151228
152229# ' get first dimension or length of object
153230# ' @param x object, matrix, vector, data.frame, ...
154- # ' @export
231+ # ' @keywords internal
155232dim1 <- function (x ){
156233 ifelse(is.null(dim(x )[1 ]), length(x ), dim(x )[1 ])
157234}
158235
159236
160237# ' get first dimension or length of object
161238# ' @param x object, matrix, vector, data.frame, ...
162- # ' @export
239+ # ' @keywords internal
163240dim2 <- function (x ){
164241 dim(x )[2 ]
165242}
166243
167244
168245# ' seq along first dimension / length
169246# ' @param x x
170- # ' @export
247+ # ' @keywords internal
171248seq_dim1 <- function (x ){
172249 seq_len(dim1(x ))
173250}
@@ -177,10 +254,11 @@ seq_dim1 <- function(x){
177254
178255
179256# ' function giving back the mode
180- # ' @export
257+
181258# ' @param x vector to get mode for
182259# ' @param multimodal wether or not all modes should be returned in case of more than one
183260# ' @param warn should the function warn about multimodal outcomes?
261+ # ' @keywords internal
184262modus <- function (x , multimodal = FALSE , warn = TRUE ) {
185263 x_unique <- unique(x )
186264 tab_x <- tabulate(match(x , x_unique ))
@@ -204,8 +282,9 @@ modus <- function(x, multimodal=FALSE, warn=TRUE) {
204282
205283
206284# ' function to get classes from e.g. lists
207- # ' @export
285+
208286# ' @param x list to get classes for
287+ # ' @keywords internal
209288classes <- function (x ){
210289 tmp <- lapply(x , class )
211290 data.frame (name = names(tmp ), class = unlist(tmp ) , row.names = NULL )
@@ -219,6 +298,7 @@ classes <- function(x){
219298# ' function to sort df by variables
220299# ' @param df data.frame to be sorted
221300# ' @param ... column names to use for sorting
301+ # ' @keywords internal
222302dp_arrange <- function (df , ... ){
223303 sorters <- as.character(as.list(match.call()))
224304 if ( length(sorters )> 2 ){
0 commit comments