Skip to content

Commit

Permalink
Turn empty vector entries to NA
Browse files Browse the repository at this point in the history
  • Loading branch information
MilesMcBain committed Nov 9, 2020
1 parent 03ea5d9 commit e569c3b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions R/clip.R
Expand Up @@ -23,6 +23,9 @@ read_clip_or_editor <- function() {
x
}




read_rstudio_editor <- function() {
if (!rstudioapi::hasFun("getSourceEditorContext")) {
return("")
Expand Down
6 changes: 6 additions & 0 deletions R/vector_paste.R
Expand Up @@ -181,5 +181,11 @@ parse_vector <- function(input_vector){
input_vector <- ifelse(grepl(pattern = "(^\".*\"$)|(^\'.*\'$)", input_vector),
yes = substr(input_vector, 2, nchar(input_vector)-1),
no = input_vector)

# set empty entries to NA
NA_entry <- function(x) {
!nzchar(trimws(x)) | x == "NA"
}
input_vector[NA_entry(input_vector)] <- NA
input_vector
}
14 changes: 14 additions & 0 deletions tests/testthat/test_vector.R
Expand Up @@ -45,6 +45,20 @@ test_that("vector_construct handles numeric correctly ", {
},
"c(7L, 8L, 7L, 6L, 6L, NA, 6L, 9L)\n"
)
expect_equal({
suppressWarnings(clipr::write_clip(content = c(7,
8,
7,
6,
6,
"",
6,
9))
)
vector_construct()
},
"c(7L, 8L, 7L, 6L, 6L, NA, 6L, 9L)\n"
)
})


Expand Down

0 comments on commit e569c3b

Please sign in to comment.