Skip to content

dskewlnorm() silently ignores non-logical 'log' values; dskewnorm() does not #156

Description

@StefanoMezzini

Problem

dskewnorm passes log straight through to sn::dsn, but dskewlnorm tests it with isTRUE() (R/skewlnorm.R:48):

lik <- if (isTRUE(log)) log_lik else exp(log_lik)

isTRUE() is FALSE for anything that isn't a length-1 logical TRUE, so numeric and character values silently fall through to the non-log branch instead of being coerced or rejected.

Reproduction

dskewnorm(1, 0, 1, 2, log = 1)     #> -0.7488043   (log density)
dskewlnorm(1, 0, 1, 2, log = 1)    #>  0.3989423   (NOT the log density)

dskewnorm(1, 0, 1, 2, log = "a")   #> Error: argument is not interpretable as logical
dskewlnorm(1, 0, 1, 2, log = "a")  #>  0.3989423   (silently ignored)

dnorm(1, log = "a")                #> -1.418939 + coercion warning  (base R reference)

The silent log = "a" case is the worst of these — a typo'd argument produces a plausible-looking number with no signal.

Suggestion

Validate log explicitly in both functions (e.g. chk_flag(log)) so the two agree with each other and fail loudly on garbage input, then use the validated flag. dskewlnorm needs to keep computing on the log scale internally for the Jacobian, so the if/exp() structure can stay — it's just the test that should change.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions