Skip to content

Commit

Permalink
Manged removing the tempdir() from the file names (so that the files …
Browse files Browse the repository at this point in the history
…are relative to root) so that it also works under Windows, other smaller corrections
  • Loading branch information
sjentsch committed Aug 4, 2023
1 parent 7a4728d commit e5554bf
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 11 deletions.
6 changes: 3 additions & 3 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* added `describe_omv` (put a title and a description at the top of a data
set), `search_omv` (finding values in a data set) and `replace_omv`
(replacing values in a data set with other values)
* improved handling in jamovi (if jvmReadWrite is run in jamovi modules, e.g.,
Rj, a new jamovi session is opened with the data set that was modified by one
of the helper functions)
* improved handling in jamovi (if jmvReadWrite is run in jamovi modules, e.g.,
`Rj`, a new jamovi session is opened with the data set that was modified by
one of the helper functions)
* improved handling of the jamovi protocol buffers (currently used for
extracting `jmv`-syntax in the data sets, but with the perspective of
creating analyses from `jmv`-syntax)
Expand Down
8 changes: 6 additions & 2 deletions R/write_omv.R
Original file line number Diff line number Diff line change
Expand Up @@ -414,12 +414,12 @@ add2ZIP <- function(fleZIP = "", crrHdl = NULL, crrFle = c(), txtOut = "", ptbOu
clsRmv()
stop(sprintf("Parameter isn\'t a file handle pointing to a file to be zipped:\n%s", trimws(utils::capture.output(utils::str(crrHdl)))))
}
crrFle <- gsub(file.path(tempdir(), ""), "", summary(crrHdl)[["description"]])
crrFle <- rmvTmp(summary(crrHdl)[["description"]])
close(crrHdl)
rm(list = deparse(substitute(crrHdl)), envir = sys.frame(-1))
# if a file name is given, open a connection, write whatever is required
} else if (is.character(crrFle)) {
crrFle[1] <- gsub(file.path(tempdir(), ""), "", crrFle[1])
crrFle[1] <- rmvTmp(crrFle[1])
if (dirname(crrFle[1]) != "." && !dir.exists(file.path(tempdir(), dirname(crrFle[1])))) dir.create(file.path(tempdir(), dirname(crrFle[1])))
crrHdl <- file(file.path(tempdir(), crrFle[1]), open = ifelse(length(crrFle) > 1, crrFle[2], "w"))
if (all(nzchar(txtOut))) {
Expand All @@ -442,3 +442,7 @@ add2ZIP <- function(fleZIP = "", crrHdl = NULL, crrFle = c(), txtOut = "", ptbOu

return(TRUE)
}

rmvTmp <- function(fleNme = "") {
return(sub("^/|^\\\\", "", sub(tempdir(), "", fleNme, fixed = TRUE)))
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,9 @@ list.files(".", "Trial.omv")
#> [1] "Trial.omv"
file.info("Trial.omv")
#> size isdir mode mtime ctime
#> Trial.omv 1723 FALSE 664 2023-08-04 14:59:50 2023-08-04 14:59:50
#> Trial.omv 1723 FALSE 664 2023-08-04 23:07:05 2023-08-04 23:07:05
#> atime uid gid uname grname
#> Trial.omv 2023-08-04 14:59:50 1000 1000 sjentsch sjentsch
#> Trial.omv 2023-08-04 23:07:05 1000 1000 sjentsch sjentsch
unlink("Trial.omv")
```

Expand Down
10 changes: 7 additions & 3 deletions man/search_omv.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/testthat/test-describe_omv.R
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ test_that("describe_omv works", {
expect_warning(expect_null(describe_omv(dtaInp = jmvReadWrite::ToothGrowth[, c("len", "supp", "dose")], fleOut = nmeOut, dtaTtl = "ToothGrowth", dtaDsc = chrDsc)))
expect_false(file.exists(nmeOut))
}

# code coverage
expect_error(describe_omv(dtaInp = jmvReadWrite::ToothGrowth[, c("len", "supp", "dose")], fleOut = nmeOut),
regexp = "^Calling describe_omv requires either the parameter dtaTtl \\(character vector\\) or the parameter dtaDsc \\(character vector or named list\\)\\.")
Expand Down

0 comments on commit e5554bf

Please sign in to comment.