Merck / Merck/pkglite

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

Open
#41 1 comment 0 reactions 1 assignee View on GitHub

@nanxstats is already working on this.

Since Dec 7, 2022.

bug
Dominant language
R
Stars
31
Forks
4
PR merge metrics
No merged PRs in 30d

Description

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 sign in '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)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.