11/*
22 * R : A Computer Language for Statistical Data Analysis
3- * Copyright (C) 1998-2023 The R Core Team.
3+ * Copyright (C) 1998-2024 The R Core Team.
44 * Copyright (C) 1995, 1996 Robert Gentleman and Ross Ihaka
55 *
66 * This program is free software; you can redistribute it and/or modify
@@ -353,7 +353,7 @@ attribute_hidden void InitOptions(void)
353353 v = CDR (v );
354354
355355 p = getenv ("R_C_BOUNDS_CHECK" );
356- R_CBoundsCheck = (p && (strcmp (p , "yes" ) == 0 )) ? 1 : 0 ;
356+ R_CBoundsCheck = (p && (strcmp (p , "yes" ) == 0 )) ? TRUE : FALSE ;
357357
358358 SET_TAG (v , install ("CBoundsCheck" ));
359359 SETCAR (v , ScalarLogical (R_CBoundsCheck ));
@@ -445,6 +445,11 @@ attribute_hidden SEXP do_getOption(SEXP call, SEXP op, SEXP args, SEXP rho)
445445
446446static Rboolean warned_on_strings_as_fact = FALSE; // -> once-per-session warning
447447
448+ static void check_TRUE_FALSE (SEXP arg , const char * chname ) {
449+ if (TYPEOF (arg ) != LGLSXP || LENGTH (arg ) != 1 || LOGICAL (arg )[0 ] == NA_LOGICAL )
450+ error (_ ("invalid value for '%s'" ), chname );
451+ }
452+
448453/* This needs to manage R_Visible */
449454attribute_hidden SEXP do_options (SEXP call , SEXP op , SEXP args , SEXP rho )
450455{
@@ -695,18 +700,12 @@ attribute_hidden SEXP do_options(SEXP call, SEXP op, SEXP args, SEXP rho)
695700 }
696701/* handle this here to avoid GetOption during error handling */
697702 else if ( streql (CHAR (namei ), "show.error.messages" ) ) {
698- if ( !isLogical (argi ) && LENGTH (argi ) != 1 )
699- error (_ ("invalid value for '%s'" ), CHAR (namei ));
700- SET_VECTOR_ELT (value , i , SetOption (tag , argi ));
703+ check_TRUE_FALSE (argi , CHAR (namei ));
701704 R_ShowErrorMessages = LOGICAL (argi )[0 ];
705+ SET_VECTOR_ELT (value , i , SetOption (tag , argi ));
702706 }
703707 else if ( streql (CHAR (namei ), "catch.script.errors" ) ) {
704- #define CHECK_TRUE_FALSE_ (_arg_ ) \
705- if (TYPEOF(_arg_) != LGLSXP || LENGTH(_arg_) != 1 || \
706- LOGICAL(_arg_)[0] == NA_LOGICAL) \
707- error(_("invalid value for '%s'"), CHAR(namei))
708-
709- CHECK_TRUE_FALSE_ (argi );
708+ check_TRUE_FALSE (argi , CHAR (namei ));
710709 SET_VECTOR_ELT (value , i , SetOption (tag , argi ));
711710 }
712711 else if (streql (CHAR (namei ), "echo" )) {
@@ -748,39 +747,29 @@ attribute_hidden SEXP do_options(SEXP call, SEXP op, SEXP args, SEXP rho)
748747 SET_VECTOR_ELT (value , i , SetOption (tag , duplicate (argi )));
749748 }
750749 else if (streql (CHAR (namei ), "warnPartialMatchDollar" )) {
751- if (TYPEOF (argi ) != LGLSXP || LENGTH (argi ) != 1 )
752- error (_ ("invalid value for '%s'" ), CHAR (namei ));
753- int k = asLogical (argi );
754- R_warn_partial_match_dollar = k ;
755- SET_VECTOR_ELT (value , i , SetOption (tag , ScalarLogical (k )));
750+ check_TRUE_FALSE (argi , CHAR (namei ));
751+ R_warn_partial_match_dollar = LOGICAL (argi )[0 ];
752+ SET_VECTOR_ELT (value , i , SetOption (tag , argi ));
756753 }
757754 else if (streql (CHAR (namei ), "warnPartialMatchArgs" )) {
758- if (TYPEOF (argi ) != LGLSXP || LENGTH (argi ) != 1 )
759- error (_ ("invalid value for '%s'" ), CHAR (namei ));
760- int k = asLogical (argi );
761- R_warn_partial_match_args = k ;
762- SET_VECTOR_ELT (value , i , SetOption (tag , ScalarLogical (k )));
755+ check_TRUE_FALSE (argi , CHAR (namei ));
756+ R_warn_partial_match_args = LOGICAL (argi )[0 ];
757+ SET_VECTOR_ELT (value , i , SetOption (tag , argi ));
763758 }
764759 else if (streql (CHAR (namei ), "warnPartialMatchAttr" )) {
765- if (TYPEOF (argi ) != LGLSXP || LENGTH (argi ) != 1 )
766- error (_ ("invalid value for '%s'" ), CHAR (namei ));
767- int k = asLogical (argi );
768- R_warn_partial_match_attr = k ;
769- SET_VECTOR_ELT (value , i , SetOption (tag , ScalarLogical (k )));
760+ check_TRUE_FALSE (argi , CHAR (namei ));
761+ R_warn_partial_match_attr = LOGICAL (argi )[0 ];
762+ SET_VECTOR_ELT (value , i , SetOption (tag , argi ));
770763 }
771764 else if (streql (CHAR (namei ), "showWarnCalls" )) {
772- if (TYPEOF (argi ) != LGLSXP || LENGTH (argi ) != 1 )
773- error (_ ("invalid value for '%s'" ), CHAR (namei ));
774- int k = asLogical (argi );
775- R_ShowWarnCalls = k ;
776- SET_VECTOR_ELT (value , i , SetOption (tag , ScalarLogical (k )));
765+ check_TRUE_FALSE (argi , CHAR (namei ));
766+ R_ShowWarnCalls = LOGICAL (argi )[0 ];
767+ SET_VECTOR_ELT (value , i , SetOption (tag , argi ));
777768 }
778769 else if (streql (CHAR (namei ), "showErrorCalls" )) {
779- if (TYPEOF (argi ) != LGLSXP || LENGTH (argi ) != 1 )
780- error (_ ("invalid value for '%s'" ), CHAR (namei ));
781- int k = asLogical (argi );
782- R_ShowErrorCalls = k ;
783- SET_VECTOR_ELT (value , i , SetOption (tag , ScalarLogical (k )));
770+ check_TRUE_FALSE (argi , CHAR (namei ));
771+ R_ShowErrorCalls = LOGICAL (argi )[0 ];
772+ SET_VECTOR_ELT (value , i , SetOption (tag , argi ));
784773 }
785774 else if (streql (CHAR (namei ), "showNCalls" )) {
786775 int k = asInteger (argi );
@@ -793,16 +782,14 @@ attribute_hidden SEXP do_options(SEXP call, SEXP op, SEXP args, SEXP rho)
793782 error (_ ("\"par.ask.default\" has been replaced by \"device.ask.default\"" ));
794783 }
795784 else if (streql (CHAR (namei ), "browserNLdisabled" )) {
796- CHECK_TRUE_FALSE_ (argi );
785+ check_TRUE_FALSE (argi , CHAR ( namei ) );
797786 R_DisableNLinBrowser = LOGICAL (argi )[0 ];
798787 SET_VECTOR_ELT (value , i , SetOption (tag , argi ));
799788 }
800789 else if (streql (CHAR (namei ), "CBoundsCheck" )) {
801- if (TYPEOF (argi ) != LGLSXP || LENGTH (argi ) != 1 )
802- error (_ ("invalid value for '%s'" ), CHAR (namei ));
803- int k = asLogical (argi );
804- R_CBoundsCheck = k ;
805- SET_VECTOR_ELT (value , i , SetOption (tag , ScalarLogical (k )));
790+ check_TRUE_FALSE (argi , CHAR (namei ));
791+ R_CBoundsCheck = LOGICAL (argi )[0 ];
792+ SET_VECTOR_ELT (value , i , SetOption (tag , argi ));
806793 }
807794 else if (streql (CHAR (namei ), "matprod" )) {
808795 SEXP s = asChar (argi );
0 commit comments