[R] Why this statement does not print anything in an if-statement that includes 'q()'?

jim holtman jholtman at gmail.com
Mon Sep 7 03:21:44 CEST 2009


You need to explicitly 'print' the second 'length' function call.
Only at the top level of the interactive session is the value of an
object printed out if you just reference the object.

On Sun, Sep 6, 2009 at 9:13 PM, Peng Yu<pengyu.ut at gmail.com> wrote:
> Hi,
>
> I run the following script. I don't understand why the second
> 'length(args)' does not show anything but the first one shows '0'. Is
> it because the command 'q()' affects anything in the if-statement.
>
> However, if I change the second 'length(args)' to
> 'print(length(args))', the script will print the length of 'args'. Can
> somebody let me know what is the difference between the 'print(x)'
> statement and the 'x' statement where 'x' is a variable?
>
> Regards,
> Peng
>
> $ Rscript not_print_in_if_block.R
>> args=commandArgs(T)
>> length(args)
> [1] 0
>>
>> if(length(args)!=3){
> +   length(args)
> +   q()
> + }
>
> ______________________________________________
> 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.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?




More information about the R-help mailing list