Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

checkfunargs: use defaults, allow ellipses #102

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions R/nloptr.R
Original file line number Diff line number Diff line change
Expand Up @@ -313,16 +313,22 @@ function( x0,
if( any(is.na(m1)) ){
mx1 = which( is.na(m1) )
for( i in 1:length(mx1) ){
stop(paste(funname, " requires argument '", fnms[mx1[i]], "' but this has not been passed to the 'nloptr' function.\n", sep = ""))
has_default = !(fnms[mx1[i]] == "")
Copy link
Owner

@astamm astamm Jan 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should be checking the value in the list here, not the name, i.e. has_default = flist[[mx1[i] + 1]] != "".

if (!has_default) {
stop(paste(funname, " requires argument '", fnms[mx1[i]], "' but this has not been passed to the 'nloptr' function.\n", sep = ""))
}
}
}
m2 = match(rnms, fnms)
if( any(is.na(m2)) ){
mx2 = which( is.na(m2) )
for( i in 1:length(mx2) ){
stop(paste(rnms[mx2[i]], "' passed to (...) in 'nloptr' but this is not required in the ", funname, " function.\n", sep = ""))
if( !("..." %in% names(flist)) ) {
m2 = match(rnms, fnms)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you run again this? It is already in m1, isn't it?

if( any(is.na(m2)) ){
mx2 = which( is.na(m2) )
for( i in 1:length(mx2) ){
stop(paste(rnms[mx2[i]], "' passed to (...) in 'nloptr' but this is not required in the ", funname, " function.\n", sep = ""))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove parenthesis around ellipsis.

}
}
}
m2 = match(rnms, fnms)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you run again this? It is already in m1, isn't it?

}
return( 0 )
}
Expand Down