- the argument
.messageof thecheck_functions is now interpolated withstring_magic()
- the type
l0has been removed. Nowcheck_arg(x, "vector")(or the like) receiving something 0-length in input will not send an error (in the previous version,l0was required). Vector length can still be checked with thelen(a,b)mechanism (thanks to @kylebutts for early bug reports).
-
to increase clarity, now the problem leading to an error is displayed in a newline with the prefix
PROBLEMin uppercase -
improve clarity of error messages involving lower than/greater than
-
improve the number of items suggested by
suggest_item
-
fix display problem in
fsignif -
increase the requirement of
stringmagicversion to be compatible with R v3.5.0 -
the
check_argfamily of functions now correctly reports the full call stack when requested -
fix bug: wrong argument name displayed when
check_valuewas used with the argument.arg_nameand an error was produced because a variable was missing in a formula. Thanks to @kylebutts, #4.
-
New set of
hookerror and warning functions for reporting in complex internal functions. These areset_hookto set a function as the hook andstop_hook/warn_hookerror and warning functions used to report as if they were called from the hooked function. -
warniandstopifor warning and stop functions with character interpolation using stringmagic
- The type
pathhas been added tocheck_arg. It is used to check paths.
- All warning and stop functions gain string interpolation with stringmagic.
- fixes
fit_screenso that it does not mess with white spaces.
- Functions
check_arg_plusandcheck_value_plusbecomecheck_set_argandcheck_set_valueto improve clarity.
-
fsignifnow displays trailing 0s appropriately and is neutral to character vectors (instead of throwing an error). -
the comparison types now can evaluate values from the calling frame:
z = 32
x = 77
try(check_value(x, "numeric scalar LE{z}"))
#> Error: in check_value(x, "numeric scalar LE{z}"):
#> Value 'x' must be a numeric scalar lower than, or equal to, 32. Problem: it is strictly greater than 32.stop_upnow accepts the argument msg which is an extra message displayed right after the error message.
-
in
check_arg_plusconversion of factors to characters now works properly. -
Fix bug in
stop_upwhen the argumentupwas not appropriately set by the user. -
fix bug in
sfillregarding the combined usage ofanchorandrightin special circumstances.
-
now
sfillaccepts 0-length vectors. -
new exported function:
fit_screen.
-
fix bugs in
sfill:-
when an anchor was provided and all characters before that were of the same length.
-
when an anchor was provided and the fill was from the right.
-
-
check_family: objects are now returned invisibly. -
new function
fsignifwhich is an alias ofsignif_plus.
- Bug when using commas or parentheses in arguments
.prefixor.argnameofcheck_value. - Bug in the error message in
check_valuewhen the argument could not be evaluated. - Bug introduced in the previous version, when checking types or equality with the option "no na"
validate_dots: nicer messages.
- IMPORTANT CHANGE: Now by default, there is
NAtolerance for the main classesvectorandmatrix(opposite to the previous behavior). The new keywordsNO NAreplace the former keywordsNA OKfor these classes.
test = function(x){
check_arg(x, "numeric vector")
}
# Before (version <= 1.1.0)
test(c(5, NA)) # => Error
# Now (version >= 1.2.0)
test(c(5, NA)) # => is OK
- IMPORTANT CHANGE: values of 0 or 1 are not valid by default anymore when the
logicaltype is requested.
test = function(x){
check_arg(x, "logical scalar")
}
# Before (version <= 1.1.0)
test(0) # => is OK
# Now (version >= 1.2.0)
test(0) # => Error, must be logical
The new behavior is equivalent to the previous behavior when the type was strict logical. Now strict logical has been removed and loose logical has been introduced which accepts 0 and 1. Why this change? I remarked that when you allow arguments of very different types, one of which was a logical scalar, it was really useful to distinguish between them safely using isTRUE or is.logical. With the previous default behavior you could have a 0 or 1 that would prevent you from doing that. Of course you could use strict logical to trigger that behavior but it was non-intuitive.
-
In
check_value: you can use the new argument.prefixto design the error message. -
Function
check_value_plusnow returns the value of the element it has checked and possibly modified.
x = "t"
y = check_value_plus(x, "match(This, Is, Raw)")
y # => "This"
fml = ~head(Petal.Length)
z = check_value_plus(fml[[2]], "evalset numeric vector", .data = iris)
z
sfillnow accepts NAs.
-
Error messages in
check_valuehave been improved. -
enumerate_itemsnow returns the empty string when 0-length vectors are in input.
-
The main class
matchcould lead the argument to lose its attributes (like names), now corrected. -
Vectors containing only NAs when NAs are tolerated could lead to a wrong error message, now corrected.
-
Bug when
check_value_pluswas called from the global environment and an error was triggered. -
Bug when
check_valuewas called and.arg_namewas provided. -
Bug when the "
..." argument containedNULLvalues. -
The developer mode now never applies to functions from packages using dreamerr
-
Behavior of argument
nmaxinenumerate_itemsis fixed. -
Type conversion of matrices returned a vector, now corrected.
-
sfill: formatting function for strings. Fills a character string up to the required length. Helps to form nice messages. -
set_up: sets the argumentupsemi-globally (i.e. throughout all calls within a function). -
set_check: turns on/off argument checking semi-globally (i.e. throughout all calls within a function).
- When devising your own message (with argument
.message), you can use the special character__ARG__. If found, it will be replaced by the appropriate argument name.
-
Message informing no NA tolerance in the types is prompted only when the error comes from NA values.
-
The developer mode catches more errors and provide more suggestions.
-
check_valuenow doesn't throw an error for missing.x.
.call_upbecomes.up-- retro-compatibility is NOT ensured.
-
Small bug that could occur for the types
"integer scalar na ok"with the argument equal toNA. -
Important bug when using features requiring evaluations in the environment. Now the default environment is set up appropriately.
-
Bug when using
var(data,env)in aformulaclass with missingdata. -
Very sneaky bug when badly forming a call to
check_argto check...in nested functions is now caught. -
In
enumerate_items, when there were many elements,quote = TRUEled to quote theXX othersthat shouldn't be quoted. Now corrected. -
In the
formulaclass, if a variable was passed as aFormula(notice the capital F), this caused an error if one-sidedness or two-sidedness were to be checked. -
Bug when in
n_letterwhen negative numbers are in. This bug propagated intocheck_arg.
This package is the outcome of over a decade of coding and developing packages in R. As a package developer I always wanted my code to be "safe": so that if a user provides arguments of the good type the functions always work, and if there's an argument of the wrong type then an informative error message is shown.
The big problem is that error handling is extremely time consuming, especially if you want to specify informative error messages stating clearly where the problem comes from. This problem is compounded when you want to offer the user flexible arguments that can be of many types. To do error handling properly in such situations is a nightmare: you end up with big if/else trees with a lot of different messages. And it doesn't improve the speed of your code! So you have little incentives to invest time in proper error handling.
This is why I developed this function. It's one line of code, and it does all the work for you. From the developer side it's super simple, and from the user side, s/he ends up with extremely informative error messages therefore saving a lot of time in debugging.