Bug 17224 - ordered() with missing x arg throws an error
Summary: ordered() with missing x arg throws an error
Status: CLOSED WONTFIX
Alias: None
Product: R
Classification: Unclassified
Component: Misc (show other bugs)
Version: R-devel (trunk)
Hardware: All All
: P5 trivial
Assignee: R-core
URL:
Depends on:
Blocks:
 
Reported: 2017-02-15 22:18 UTC by Richard Cotton
Modified: 2017-03-29 23:04 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Richard Cotton 2017-02-15 22:18:52 UTC
factor() returns a zero-length factor, as does factor(ordered = TRUE).

However, ordered() throws an error:

Error in factor(x, ..., ordered = TRUE) : 
  argument "x" is missing, with no default

This is sufficiently odd that I think that the behavior of ordered() either 

1. needs changing to match factor(), or
2. documenting with an example on the ?factor page.

In the former case, defining ordered() as

ordered <- function (...) {
  factor(..., ordered = TRUE)
}

solves the problem.
Comment 1 Duncan Murdoch 2017-03-29 23:04:30 UTC
This is how it's documented:  there's a default for x in factor(), but not in ordered().  

The documentation also says "For compatibility with S there is also a function ordered."  I don't know if S has/had this oddity, but I don't think it's worth changing.  

If you want a zero length ordered factor, use factor(ordered = TRUE), or ordered(character()).