Skip to content

Commit ff82674

Browse files
committed
Fix for #172
1 parent bafbb36 commit ff82674

File tree

5 files changed

+39
-2
lines changed

5 files changed

+39
-2
lines changed

R/libname.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ libname <- function(name, directory_path, engine = "rds",
375375
dat <- exec_spec(dat, import_specs, nm)
376376

377377
} else if (ext == "sas7bdat") {
378-
378+
379379
dat <- read_sas(fp)
380380
if (!is.null(import_specs))
381381
dat <- exec_spec(dat, import_specs, nm)

R/utilities.R

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ get_colspec_csv <- function(type_string) {
397397
#' @noRd
398398
exec_spec <- function(x, spcs, nm) {
399399

400+
# browser()
400401
ret <- x
401402

402403
if (!is.null(spcs)) {
@@ -468,7 +469,9 @@ exec_spec <- function(x, spcs, nm) {
468469
attr(ret[[nm]], atnm) <- attr(x[[nm]], atnm)
469470
} else {
470471
if (is.null(colspcs[[nm]])) {
471-
attr(ret[[nm]], atnm) <- attr(x[[nm]], atnm)
472+
if (nrow(x) > 0) {
473+
attr(ret[[nm]], atnm) <- attr(x[[nm]], atnm)
474+
}
472475
}
473476
}
474477

128 KB
Binary file not shown.

tests/testthat/test-datastep.R

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1785,3 +1785,25 @@ test_that("ds50: works as expected with source.all().", {
17851785

17861786
})
17871787

1788+
1789+
test_that("ds51: delete() works with NA in data frame.", {
1790+
1791+
1792+
df1 <- data.frame(
1793+
var = c(NA,0),
1794+
bar = c(0, 1)
1795+
)
1796+
1797+
1798+
datastep(df1,
1799+
{
1800+
if (var %eq% 0) {
1801+
delete()
1802+
}
1803+
}) -> df2
1804+
1805+
1806+
expect_equal(TRUE, TRUE)
1807+
1808+
})
1809+

tests/testthat/test-libname.R

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,18 @@ test_that("lib27: labels on data are retained after where clause", {
590590

591591

592592

593+
test_that("lib28: empty dataset works as expected", {
594+
595+
pth <- file.path(base_path, "empty")
596+
597+
libname(testme, pth, "sas7bdat")
598+
599+
600+
# No error
601+
expect_equal(TRUE, TRUE)
602+
603+
})
604+
593605

594606
#
595607
# test_that("lib24: lib_export() creates new library.", {

0 commit comments

Comments
 (0)