Skip to content

Commit 6b76bea

Browse files
Use match.arg() for arg validation
1 parent 4936e45 commit 6b76bea

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

R/fwrite.R

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,10 @@ fwrite = function(x, file="", append=FALSE, quote="auto",
1919
if (length(encoding) != 1L || !encoding %chin% c("", "UTF-8", "native")) {
2020
stopf("Argument 'encoding' must be '', 'UTF-8' or 'native'.")
2121
}
22-
if (missing(qmethod)) qmethod = qmethod[1L]
23-
if (missing(compress)) compress = compress[1L]
24-
if (missing(compressLevel)) compressLevel = 6L
25-
if (missing(dateTimeAs)) { dateTimeAs = dateTimeAs[1L] }
26-
else if (length(dateTimeAs)>1L) stopf("dateTimeAs must be a single string")
27-
dateTimeAs = chmatch(dateTimeAs, c("ISO","squash","epoch","write.csv"))-1L
28-
if (is.na(dateTimeAs)) stopf("dateTimeAs must be 'ISO','squash','epoch' or 'write.csv'")
22+
qmethod = match.arg(qmethod)
23+
compress = match.arg(compress)
24+
dateTimeAs = match.arg(dateTimeAs)
25+
dateTimeAs = chmatch(dateTimeAs, c("ISO", "squash", "epoch", "write.csv"))-1L
2926
if (!missing(logical01) && !missing(logicalAsInt))
3027
stopf("logicalAsInt has been renamed logical01. Use logical01 only, not both.")
3128
if (!missing(logicalAsInt)) {

0 commit comments

Comments
 (0)