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

Catching "line X did not have Y elements" #16

Closed
grimbough opened this issue Jun 3, 2019 · 1 comment
Closed

Catching "line X did not have Y elements" #16

grimbough opened this issue Jun 3, 2019 · 1 comment
Assignees

Comments

@grimbough
Copy link
Owner

Example: https://support.bioconductor.org/p/121356/

Encountered several times when returned values contain non-escaped \n. This is interpreted as a new row and breaks the table reading.

host = "https://www.ensembl.org:443/biomart/martservice?"
query = "<?xml version='1.0' encoding='UTF-8'?><!DOCTYPE Query>
<Query  virtualSchemaName = 'default' uniqueRows = '1' count = '0' datasetConfigVersion = '0.6' header='1' requestid= 'biomaRt' formatter = 'TSV'>
<Dataset name = 'hsapiens_gene_ensembl'><Attribute name = 'ensembl_gene_id'/>
<Attribute name = 'hgnc_symbol'/>
<Attribute name = 'go_id'/>
<Attribute name = 'name_1006'/>
<Attribute name = 'definition_1006'/>
<Filter name = \"ensembl_gene_id\" value = \"ENSG00000100036\" /></Dataset></Query>"
res <- httr::POST(url = host, body = list(query = query), 
                  httr::set_cookies(.cookies = c(redirect_mirror = "no")))
con = textConnection(httr::content(res))
result = read.table(con, sep=",", header=TRUE, quote = "\"", comment.char = "", as.is=TRUE, check.names = TRUE, allowEscapes = TRUE)

Solution: The HTML version of the output seems to handle this correctly. This is larger and more complex to parse, but could be used as a backup if TSV is failing.

@grimbough grimbough self-assigned this Jun 3, 2019
@grimbough
Copy link
Owner Author

This is now caught in

result <- tryCatch(read.table(con, sep="\t", header=callHeader, quote = quote,
and handled by the internal function .fetchHTMLresults()

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

No branches or pull requests

1 participant