Quantcast

Override/Insert (Change) a value (default value) inside a function

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Override/Insert (Change) a value (default value) inside a function

R help mailing list-2
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  |  [hidden email]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Override/Insert (Change) a value (default value) inside a function

Franklin Bretschneider-2
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
[hidden email]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [FORGED] Override/Insert (Change) a value (default value) inside a function

Rolf Turner
In reply to this post by R help mailing list-2
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

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Override/Insert (Change) a value (default value) inside a function

R help mailing list-2
In reply to this post by Franklin Bretschneider-2
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   |  [hidden email]


----- Original Message -----
From: Franklin Bretschneider <[hidden email]>
To: Mohammad Tanvir Ahamed <[hidden email]>; R-help groep <[hidden email]>
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
[hidden email]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Override/Insert (Change) a value (default value) inside a function

Rolf Turner
On 12/03/17 11:11, Mohammad Tanvir Ahamed wrote:

> 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 ?

As the problem is stated, you cannot solve it.

Depending on circumstances, there are various approaches that you could
take.  One would be to get the package source, edit the "myplot"
function so that it has a "..." argument, and then install the edited
version.

Since we don't know your circumstances, nor what it is that you really
need to accomplish (your description of the problem is very vague), it
is difficult to make suggestions.

cheers,

Rolf Turner

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Override/Insert (Change) a value (default value) inside a function

Jeff Newmiller
In reply to this post by R help mailing list-2
You can't.  You can skip the package and roll your own functions if the package functions are not written to use ...
--
Sent from my phone. Please excuse my brevity.

On March 11, 2017 2:11:39 PM PST, Mohammad Tanvir Ahamed via R-help <[hidden email]> wrote:

>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   |  [hidden email]
>
>
>----- Original Message -----
>From: Franklin Bretschneider <[hidden email]>
>To: Mohammad Tanvir Ahamed <[hidden email]>; R-help groep
><[hidden email]>
>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
>[hidden email]
>
>______________________________________________
>[hidden email] mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Override/Insert (Change) a value (default value) inside a function

plangfelder
In reply to this post by R help mailing list-2
On Sat, Mar 11, 2017 at 2:11 PM, Mohammad Tanvir Ahamed via R-help
<[hidden email]> wrote:
> 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!!

The easiest solution __is__ to change the function inside the package.
If the license of the package allows it and your coding skills are up
to it, download the source of the package, make the necessary
modification in the code, and use that. If you make the modifications
so that they are useful for others, you could email the package
maintainer with your code and suggest that he/she incorporates it in
the package for wider release.

Peter

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Override/Insert (Change) a value (default value) inside a function

Rui Barradas
In reply to this post by R help mailing list-2
Hello,

Just to add to what others have said, I believe you haven't understood
the dots argument. Where you to change the function in the package and
the correct form would be

myplot <- function(x,y, ...) { plot(x,y,...) }

Hope this helps,

Rui Barradas

Em 11-03-2017 22:11, Mohammad Tanvir Ahamed via R-help escreveu:

> 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   |  [hidden email]
>
>
> ----- Original Message -----
> From: Franklin Bretschneider <[hidden email]>
> To: Mohammad Tanvir Ahamed <[hidden email]>; R-help groep <[hidden email]>
> 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
> [hidden email]
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Loading...