specifyInput add check for missing #38
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hello,
so I was tasked with creating synthetic data for a dataset with out
hhidandhhsize. And I stumbled upon two errors related to hhid.Let's use example with
eusilcdata.The code below is working properly.
1. Now let’s take a look at a similar code. But
hhidandhhsizeare absent.Ok, so there is an error argument
"hhid" is missing, with no defaultThe function definition of
specifyInputsays:This suggests that
hhidis optional, because it has a default valueNULL.Inside the function, there's this block:
So why do we get this error
"hhid" is missing, with no defaultthen?Problem here is not
hhid = NULL, but thathhidis missing altogether. Which is exactly what the error message explicitly says.When a parameter is not passed at all, inside the function,
hhidis not yet evaluated — it is notNULL— it is missing.So inside the function, the condition
is.null(hhid)is evaluted with error argument"hhid" is missing, with no default, becausehhidis missing — not provided yet at all.On an object that is not defined → hence the error.
So I recommend adding these checks at the beginning of the function:
This way, the function will work as expected and will not display an error message when
hhidorhhsizeare not provided.So I added it to my fork:
Now it works as expected.
2. However, there was another error when the parameters were included, but set to
NULL.the error message says
argument is of length zero.When we explicitly write
hhid = NULLThe function see:
Logical test is not properly evaluated → hence the error.
But all this was properly handled by adding the check for
missing(hhid)at the beginning of the function.