Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

adjust asreml to work in newer versions #5

Open
bonifazi opened this issue Aug 1, 2023 · 1 comment
Open

adjust asreml to work in newer versions #5

bonifazi opened this issue Aug 1, 2023 · 1 comment
Assignees

Comments

@bonifazi
Copy link
Owner

bonifazi commented Aug 1, 2023

No description provided.

@bonifazi bonifazi self-assigned this Aug 1, 2023
@bonifazi
Copy link
Owner Author

bonifazi commented Aug 1, 2023

Newer version of asreml seems to have an header.
In that case check that indeed first line is all character or not all numeric, then proceed with the logic of skipping the header in fread.

suggestion from chatgpt (too redundant IMO, see if can be improved):

Read the first line of the file

first_line <- readLines(infile, n = 1)

Check if the first line contains numeric data

if (all(is.numeric(scan(text = first_line, quiet = TRUE)))) {

First line contains numeric data, no header, skip = 0

sln <- fread(infile,
header = FALSE,
stringsAsFactors = FALSE,
strip.white = TRUE,
col.names = col_names,
colClasses = list(character = c(1, 2), double = c(3:4))
)
} else {

First line contains non-numeric data, assume it's a header, skip = 1

sln <- fread(infile,
header = FALSE,
skip = 1,
stringsAsFactors = FALSE,
strip.white = TRUE,
col.names = col_names,
colClasses = list(character = c(1, 2), double = c(3:4))
)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant