[R] Problem with a if statement inside a function

Sarah Goslee sarah.goslee at gmail.com
Thu Jun 9 18:33:35 CEST 2011


On Thu, Jun 9, 2011 at 12:27 PM, Abraham Mathew <abraham at thisorthat.com> wrote:
>
> I passed it as an argument to the function because every week I'll  need to add keywords to the lst, and that function will make the process more automated.

But it doesn't. lst is hard-coded within your function, so passing
something, anything, named lst to your function is irrelevant.

But back to your original question, you really need to provide the
list with a short version that we can run. Diagnosing such a long mass
of code without even being able to try it out is very difficult.

Sarah

>
>
> On Thu, Jun 9, 2011 at 10:21 AM, Sarah Goslee <sarah.goslee at gmail.com> wrote:
>>
>> On Thu, Jun 9, 2011 at 11:53 AM, Abraham Mathew <abraham at thisorthat.com> wrote:
>> >
>> > lst is a list within the function.
>>
>> Then why is it passed as an argument to the function? You can have a
>> function with no arguments, but in this case why, since it would do
>> exactly the same thing every time?
>>
>> Arguments are for passing information to a function that varies each
>> time the function is run.
>>
>> Sarah
>>
>>
>> > Good point about the working directory.
>> >
>> > Thanks
>> > Abraham
>> >
>> >
>> >
>> > On Thu, Jun 9, 2011 at 9:35 AM, Sarah Goslee <sarah.goslee at gmail.com> wrote:
>> >>
>> >> Can you boil that down into a short reproducible example?
>> >>
>> >> For instance, when you run your function at the end
>> >> > newdf <- myfunc(lst)
>> >>
>> >> I can't run it myself because I don't know what lst is. Although it seems not
>> >> to matter - what are you passing as an argument to the function, since
>> >> it seems to
>> >> be completely overwritten.
>> >>
>> >> Also, calling setwd() within a function seems like a bad idea, because
>> >> it guarantees that nobody but you can ever use it. And why would you,
>> >> rather than passing the working directory as an argument if it's
>> >> crucial?
>> >>
>> >> Sarah
>> >>
>> >>
>



More information about the R-help mailing list