Skip to content

Commit 0abb85c

Browse files
authored
Merge pull request #20 from duttashi/develop
A user defined function to test the function arguments
2 parents b7174b3 + 0937cf9 commit 0abb85c

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# create a function to test the arguments
2+
3+
# clean the workspace
4+
rm(list = ls())
5+
testArgs<- function(data){
6+
7+
if (!is.matrix(data) & !is.data.frame(data)) {
8+
stop("The data must be a matrix or a data frame.")
9+
}
10+
else{
11+
str(data)
12+
print("All ok")
13+
}
14+
}
15+
16+
# create some test data to test the function
17+
# a vector
18+
aa<- c(1:10)
19+
testArgs(aa)
20+
21+
# a data frame
22+
df<- data.frame(x=c(1:10),y=c(11:20))
23+
testArgs(df)

0 commit comments

Comments
 (0)