[R] How to handle empty arguments

R. Michael Weylandt michael.weylandt at gmail.com
Thu Nov 10 02:53:10 CET 2011


Perhaps the missing() command will help in regards to suggestion a.
I'd caution against b for obvious reasons, though I think
options(error = XXXX) can get you that behavior (you'll have to figure
out what XXX is, I have never tried to lessen my error messages...)

Michael

On Tue, Nov 8, 2011 at 3:04 PM, Alaios <alaios at yahoo.com> wrote:
> Dear all,
> I am having a data stucture that contains Products and Time Stamps,
>
> I have made also two lists
> ProductList=list(c('Example1','Example2'...)
> TimeStamp=list(c("1990-02-03 12:57:60"),c("1990-02-03 12:57:60"),
>
> then I have made few functions that call each other
>
> do_analysis_for_all the data<-function(arguments){
>    .....
>    return(lapply(ProductList,do_analysis_for_one_product_list_for_all_time_stamps)
> }
>
> do_analysis_for_one_product_list_for_all_time_stamps<-function(arguments){
>     ....
>    return(lapply(TimeStamps,do_analysis_for_one_product_list_for_one_time_stamps)
> }
>
> (this is mostly just an algorithm to show you the main logic).
>
>
> as one is getting down to the chain I have described, there are functions that chop the data as requested. For example for a specific TimeFram one will get the entries that correspond to the specific dates.
>
> The problem I have though is that sometimes (is not too often) there are no entries for a specific interval and thus the next function will rely on the "chopped" data will explode with an error.
>
> I want to ask you for a clear solution to handle this cases
>
> I have two ideas in mind
>
> a). I change all the function in my code so to check that the input argument is empty (how to do that?) and in that case I return an empty list
>
> b) I change nothing to the code and I ask kindly from the R in that case to return a lovely error message (Best is to find it saved in the list that lapply returns) and continue to the next case. I have tried earlier to add the try(myfunction,silent=TRUE) but I ended up changing all my code with the try(..) which of course is a bit of "dirty" solution. Do you know if I can ask "globally" R (perhaps add some directive in the beginning of my file) to handle all these errors in a silent manner so to skip them.
>
> What should I try to a or b and why?
>
> I would like to thank you in advance for your time spent to read this email
>
> B.R
>
> Alex
>        [[alternative HTML version deleted]]
>
>
> ______________________________________________
> R-help at r-project.org mailing list
> 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.
>
>



More information about the R-help mailing list