Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

seg_char and any seq(...) - dependent function #41

Open
SHAESEN2 opened this issue Oct 17, 2022 · 1 comment
Open

seg_char and any seq(...) - dependent function #41

SHAESEN2 opened this issue Oct 17, 2022 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@SHAESEN2
Copy link

It would be helpful to include checks before sending code into a seq(...) function.
In my case I had an empty file in a folder and got an error while running the pack function:

Error in seq.default(from = 1L, to = nchars, by = nmax) :
wrong # 'by' argument

I traced it all the way to

seg_char <- function(x, nmax) {
    nchars <- length(x)
    pos <- seq(from = 1L, to = nchars, by = nmax)
    short <- nchars <= nmax
    nlines <- if (short) 1L else length(pos)
    pos_start <- if (short) 1L else pos[seq_len(nlines)]
    pos_end <- if (short) nchars else c(pos[2L:nlines] - 1L, nchars)
    lapply(seq_len(nlines), function(i) x[pos_start[i]:pos_end[i]])
  }

Since the binary file had 0 bytes and no content the seq(from = 1L, to = 0, by = 64) gave the error. I propose to built in a safety net to check if files have content (eg remove empty files in a sanitize function, eg if nchars>1 then do ... else give informative error to the user to investigate)

@nanxstats nanxstats self-assigned this Dec 7, 2022
@nanxstats
Copy link
Collaborator

Nice catch! Thanks so much for finding this edge case. Mostly it sounds like a relatively simple fix - perhaps keeping the empty file is still desirable. I will probably patch it in the next few months and update the progress here.

@nanxstats nanxstats added the bug Something isn't working label May 12, 2023
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants