forked from cran/RTest
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathutils.examples.R
executable file
·131 lines (110 loc) · 4.47 KB
/
utils.examples.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
###################################################################################################
# RTest #
###################################################################################################
# #
# Example functions for "generic" adapter #
# #
# Date: 09 - Dec - 2018 #
# Author: Sebastian Wolf ([email protected]) #
# #
###################################################################################################
#' Function changing a data frame by adding a column
#'
#' @param data (\code{data.frame}) Any data frame with numeric values
#' @param mult (\code{numeric}) Any numeric value (length == 1)
#'
#' @return A data.frame with an additional column sum that
#' is the rowwise sum multiplied by \code{mult}
#'
#' @export
#' @author Sebastian Wolf \email{sebastian@@mail-wolf.de}
example_data_frame <- function(
data = data.frame(x=c(1,2),y=c(1,2)),
mult = 1
){
data[,"sum"] <- apply(data,1,function(x){sum(x)*mult})
return(data)
}
#' Function returning the Roche logo as an image at tempdir
#'
#' @param name \code{character} The name of the output image
#'
#' @return The file path to a temporar file with the given
#' name that will contain the Roche_Logo.png that
#' comes with RTest/images
#'
#' @export
#' @author Sebastian Wolf \email{sebastian@@mail-wolf.de}
example_image <- function(name="Roche_logo.png"){
input <- list.files(find.package("RTest"),recursive = T,pattern="Roche_Logo",full.names=T)[1]
output <- file.path(tempdir(),name)
file.copy(from = input, to=output,overwrite=T)
return(output)
}
#' Function returning a list with three values
#'
#' @param name_1 (\code{character}) Name of the first list element
#' @param value_2 (\code{numeric}) Value of the second list element
#'
#' @return A list with three elements, a generic data frame
#' inside the element \code{data.frame} a list element with
#' the value "VALUE1" inside the element with name of
#' parameter \code{name_1} and an item with the name "NAME2"
#' and the value of \code{value_2} inside.
#'
#' @export
#' @author Sebastian Wolf \email{sebastian@@mail-wolf.de}
example_list <- function(name_1 = "NAME1",value_2 = 1){
return_value <- list()
return_value[[name_1]] <- "VALUE1"
return_value[["NAME2"]] <- value_2
return_value[["data.frame"]] <- data.frame(x=c(1,2),y=c(1,2))
return(return_value)
}
#' Function returning a list with three values and large DF
#'
#' @param name_1 (\code{character}) Name of the first list element
#' @param value_2 (\code{numeric}) Value of the second list element
#'
#' @return A list with three elements, a generic data frame
#' inside the element \code{data.frame} a list element with
#' the value "VALUE1" inside the element with name of
#' parameter \code{name_1} and an item with the name "NAME2"
#' and the value of \code{value_2} inside.
#'
#' @name example_list_large
#'
#' @export
#' @author Sebastian Wolf \email{sebastian@@mail-wolf.de}
example_list_large <- function(name_1 = "NAME1",value_2 = 1){
warning('{"Testing":["might take long"]}')
return_value <- list()
return_value[[name_1]] <- "VALUE1"
return_value[["NAME2"]] <- value_2
return_value[["data.frame"]] <- data.frame(x=rep(1,290),y=rep(2,290))
return(return_value)
}
#' Function returning a character vector of length "rep"
#'
#' @param rep (\code{numeric}) Number of repetitions
#'
#' @return character vector containing \code{rep} times
#' the word "RTest"
#'
#' @export
#' @author Sebastian Wolf \email{sebastian@@mail-wolf.de}
example_vector <- function(rep = 5){
rep("RTest",times=rep)
}
#' Function returning relative difference of X and Y
#'
#' @param x (\code{numeric}) X-value
#' @param y (\code{numeric}) Y-value
#'
#' @return \code{(X-Y)/(X)}
#'
#' @export
#' @author Sebastian Wolf \email{sebastian@@mail-wolf.de}
example_variable <- function(x=1.2,y=1){
(x-y)/(x)
}