[R] Calling R object from R function

R. Michael Weylandt michael.weylandt at gmail.com
Wed Nov 7 23:56:22 CET 2012


On Wed, Nov 7, 2012 at 6:40 PM, Fares Said <frespider at hotmail.com> wrote:
> Hi Michael,
>
> Can you explain more please why it want return an error?
>
> vectx and vectz just a vector of columns index  I change them when ever is
> required so I want use them at the begin of my get.m function before I do
> the resampling. I only need these index and nothing else from that M11
> function nothing else.
>
> Can you help please?
>
>> From: michael.weylandt at gmail.com
>> Date: Wed, 7 Nov 2012 18:28:38 +0000
>> Subject: Re: [R] Calling R object from R function
>> To: frespider at hotmail.com
>> CC: r-help at r-project.org
>>
>> On Wed, Nov 7, 2012 at 3:31 PM, frespider <frespider at hotmail.com> wrote:
>> > Hi,
>> >
>> > Can you please help me with this please?
>> >
>> > What I am trying to do is call a vector from R function and used in the
>> > new
>> > function
>> >
>> > So I create 4 functions with these arguments
>> > M11 <- function(TrainData,TestData,mdat,nsam) {
>> > ls <- list()
>> > I have few statments one of them is
>> > vectx <- c(,1,2,3,4,5,6,6)
>> > vectz <- c(12,34,5,6,78,9,90)
>> > and then................
>> > ls(vectx=vtecx,vectz=vectz)
>> > return(ls)
>> > }
>>
>> This is not valid assignment to a list. In fact, I'm rather surprised
>> it doesn't throw an error...
>>
>> Michael

Hi Fares,

A few points of etiquette: firstly, it's best to keep your posts on
the list so others can help. If you want individual/private help, it's
best to request it specifically or though a consulting arrangement.

Secondly, your code is not reproducible:
http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example
-- nor is it entirely clear to me what it's trying to do. Please try
to work up something reproducible and nicely commented.

As to the error with ls() as you use it:

ls <- list()
ls(x = 5) # Gives an error.

Note that the ls you create shadows the important function ls(). But
even if you don't do that, there's an error because x = is not a
parameter of ls().

Cheers,
Michael




More information about the R-help mailing list