forked from agbarnett/helping.funders
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpaste5.R
More file actions
25 lines (23 loc) · 698 Bytes
/
Copy pathpaste5.R
File metadata and controls
25 lines (23 loc) · 698 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# paste5.R
# from here: https://stackoverflow.com/questions/13673894/suppress-nas-in-paste
# May 2017
paste5 <- function(..., sep = " ", collapse = NULL, na.rm = T) {
if (na.rm == F)
paste(..., sep = sep, collapse = collapse)
else
if (na.rm == T) {
paste.na <- function(x, sep) {
x <- gsub("^\\s+|\\s+$", "", x)
ret <- paste(na.omit(x), collapse = sep)
is.na(ret) <- ret == ""
return(ret)
}
df <- data.frame(..., stringsAsFactors = F)
ret <- apply(df, 1, FUN = function(x) paste.na(x, sep))
if (is.null(collapse))
ret
else {
paste.na(ret, sep = collapse)
}
}
}