From e6c2671ef1abf245a5f01b8e6f948236c8b6c033 Mon Sep 17 00:00:00 2001 From: Ashish Dutt Date: Sat, 14 Jul 2018 14:38:31 +0800 Subject: [PATCH 1/2] initial commit --- .../basic concepts/function-argument_test.R | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 scripts/basic concepts/function-argument_test.R diff --git a/scripts/basic concepts/function-argument_test.R b/scripts/basic concepts/function-argument_test.R new file mode 100644 index 0000000..955ca38 --- /dev/null +++ b/scripts/basic concepts/function-argument_test.R @@ -0,0 +1,25 @@ +# create a function to test the arguments + +# clean the workspace +rm(list = ls()) +testArgs<- function(data){ + + # if(!is.matrix(aargu) | !(is.data.frame(aargu))){ + # stop("The data must be a matrix format or data frame format") + # } + if (!is.matrix(data) & !is.data.frame(data)) { + stop("The data must be a matrix or a data frame.") + } + else{ + str(data) + print("All ok") + } +} + +aa<- c(1:10) +testArgs(aa) + +?data.frame +df<- data.frame(x=c(1:10),y=c(11:20)) +df +testArgs(df) From 0937cf9bc7e466e02ffda6eab1be4cfaaf0adf06 Mon Sep 17 00:00:00 2001 From: Ashish Dutt Date: Sat, 14 Jul 2018 14:44:15 +0800 Subject: [PATCH 2/2] initial commit --- scripts/basic concepts/function-argument_test.R | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/scripts/basic concepts/function-argument_test.R b/scripts/basic concepts/function-argument_test.R index 955ca38..1004580 100644 --- a/scripts/basic concepts/function-argument_test.R +++ b/scripts/basic concepts/function-argument_test.R @@ -4,9 +4,6 @@ rm(list = ls()) testArgs<- function(data){ - # if(!is.matrix(aargu) | !(is.data.frame(aargu))){ - # stop("The data must be a matrix format or data frame format") - # } if (!is.matrix(data) & !is.data.frame(data)) { stop("The data must be a matrix or a data frame.") } @@ -16,10 +13,11 @@ testArgs<- function(data){ } } +# create some test data to test the function +# a vector aa<- c(1:10) testArgs(aa) -?data.frame +# a data frame df<- data.frame(x=c(1:10),y=c(11:20)) -df testArgs(df)