Is NaN the right value for xml_find_num() of an absent XPath?

Aperta
#435 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
r
Ambito
api

Direzione di ricerca

Start by comparing the behavior of xml_find_num(), xml_find_int(), and xml_find_first() for an absent XPath such as number(//NODE/@line1). Read the implementations and existing tests for these entry points, then determine and document a consistent missing-value behavior, including the NaN-to-integer case.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug xpath :walking_man:

Encountered when trying to convert some as.integer(xml_find_num()) usage. Consider:

x1 <- xml2::read_xml('<NODE line1="1">x</NODE>')
x2 <- xml2::read_xml('<NON-NODE line1="1">x</NON-NODE>')

xml2::xml_find_num(x1, "number(//NODE/@line1)")
# [1] 1
xml2::xml_find_num(x2, "number(//NODE/@line1)")
# [1] NaN
xml2::xml_find_int(x2, "number(//NODE/@line1)")
# Error in `xml2::xml_find_int()`:
# ! Element at path `number(//NODE/@line1)` must be a whole number, not `NaN`.
# Run `rlang::last_trace()` to see where the error occurred.
xml2::xml_find_first(x2, "//NODE/@line1")
# {xml_missing}
# <NA>

I would have expected NA to show up from xml_find_num() if xml_find_first() is returning xml_missing.

Either way, the inconsistency of xml_find_int() should be fixed. Since as.integer(NaN) is NA_integer_, shall we return that directly instead of looking at check_number_whole()?

Lingua principale
R
Stelle
227
Fork
86
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di r-lib/xml2

Tutte le issue di r-lib/xml2

Issue simili

Altre issue su R

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.