Mohammad Tanvir Ahamed
2017-Mar-11 21:26 UTC
[R] Override/Insert (Change) a value (default value) inside a function
Hi!, Lets I have a function form a package. The function is, as an example, myplot <- function(x,y) { plot(x,y) } Now I can use the function according to function's defined argument. x<- sort(runif(200)) y<- 1:200 myplot(x,y) Now I want to input extra argument or override default value of plot inside the function myplot. If I use myplot (x,y, col = "red", cex = 0.1 ) it does not work . I clearly understand , why it does not work . But in this situation how can i solve the problem ? I will be grateful if any one can help. Thanks in advance !! Tanvir Ahamed G?teborg, Sweden | mashranga at yahoo.com
Franklin Bretschneider
2017-Mar-11 21:45 UTC
[R] Override/Insert (Change) a value (default value) inside a function
Dear Mohammad Tanvir Ahamed, Re:> Hi!, > > Lets I have a function form a package. > The function is, as an example, > > myplot <- function(x,y) { plot(x,y) } > > > Now I can use the function according to function's defined argument. > > x<- sort(runif(200)) > y<- 1:200 > myplot(x,y) > > Now I want to input extra argument or override default value of plot inside the function myplot. > > If I use myplot (x,y, col = "red", cex = 0.1 ) it does not work . I clearly understand , why it does not work . > But in this situation how can i solve the problem ? >That's where the three-dot argument is for. See "Introduction to R", paragraph 10.4 The ??? argument. Succes and best regards, Frank --- Franklin Bretschneider Dept of Biology Utrecht University bretschr at xs4all.nl
Rolf Turner
2017-Mar-11 21:46 UTC
[R] [FORGED] Override/Insert (Change) a value (default value) inside a function
On 12/03/17 10:26, Mohammad Tanvir Ahamed via R-help wrote:> Hi!, > > Lets I have a function form a package. > The function is, as an example, > > myplot <- function(x,y) { plot(x,y) } > > > Now I can use the function according to function's defined argument. > > x<- sort(runif(200)) > y<- 1:200 > myplot(x,y) > > Now I want to input extra argument or override default value of plot inside the function myplot. > > If I use myplot (x,y, col = "red", cex = 0.1 ) it does not work . I clearly understand , why it does not work . > But in this situation how can i solve the problem ? > > I will be grateful if any one can help. > Thanks in advance !!Learn about the "..." argument. See e.g. section 10.4 of "An Introduction to R" (first item under R home page -> Documentation -> Manuals). cheers, Rolf Turner -- Technical Editor ANZJS Department of Statistics University of Auckland Phone: +64-9-373-7599 ext. 88276
Mohammad Tanvir Ahamed
2017-Mar-11 22:11 UTC
[R] Override/Insert (Change) a value (default value) inside a function
Thanks for reply. as I said , the function in the package is like myplot <- function(x,y) { plot(x,y) } not like myplot <- function(x,y) { plot(x,y,...) } And I cant change the function inside the package!! So , in this case how to solve the problem ? Tanvir Ahamed G?teborg, Sweden | mashranga at yahoo.com ----- Original Message ----- From: Franklin Bretschneider <bretschr at xs4all.nl> To: Mohammad Tanvir Ahamed <mashranga at yahoo.com>; R-help groep <r-help at r-project.org> Sent: Saturday, 11 March 2017, 22:45 Subject: Re: [R] Override/Insert (Change) a value (default value) inside a function Dear Mohammad Tanvir Ahamed, Re:> Hi!, > > Lets I have a function form a package. > The function is, as an example, > > myplot <- function(x,y) { plot(x,y) } > > > Now I can use the function according to function's defined argument. > > x<- sort(runif(200)) > y<- 1:200 > myplot(x,y) > > Now I want to input extra argument or override default value of plot inside the function myplot. > > If I use myplot (x,y, col = "red", cex = 0.1 ) it does not work . I clearly understand , why it does not work . > But in this situation how can i solve the problem ? >That's where the three-dot argument is for. See "Introduction to R", paragraph 10.4 The ??? argument. Succes and best regards, Frank --- Franklin Bretschneider Dept of Biology Utrecht University bretschr at xs4all.nl