read_xml_num: Lacks Example and Detailed Explanation

オープン
#415 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
38/100
issue の種類
ドキュメント
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
r
領域
documentation

調査の方向性

Begin by locating the existing documentation entry for read_xml_num and compare it with the xml_find_num calls shown here. Resolve the naming and behavior ambiguity, then add a runnable example and explanation covering the reported error and missing-year case.

索引モデルが issue の本文から書いたものです。

説明

documentation xpath :walking_man:

Function read_xml_num

Documentation

The function lacks an example and a detailed explanation. Therefore, I am unsure what it actually does or how to actually use it.

All examples generate an error:

Error: result of type: ‘list’, not numeric

Other Issues

This issue is also related to issue:
https://github.com/r-lib/xml2/issues/356

Example

I try to extract the year from the corresponding node. Some records may miss the value for the year, but it makes sense to process the set sequentially and retrieve an NA. Skipping such nodes would generate frame-shifts and scramble the data (as I am actually interested in the whole record, in this example it includes the Title & Year). The straightforward solution: xml_find_num, but it doesn't look to do this.

library("xml2")

### All Years Present

sx = "<?xml version=\"1.0\" ?>
<ArticleSet>
<a><b>Title 1</b>
	<c>2023</c>
</a>
<a><b>Title 2</b>
	<c>2022</c>
</a>
<a><b>Title 3</b>
	<c>2023</c>
</a>
</ArticleSet>"

x = read_xml(sx)

ns = xml_find_all(x, "/ArticleSet/a")
ns

xml_find_all(ns, ".//c/text()")
xml_find_num(ns, ".//c/text()")
xml_find_num(ns, ".//c")


####################
### One Year Missing

sx = "<?xml version=\"1.0\" ?>
<ArticleSet>
<a><b>Title 1</b>
	<c>2023</c>
</a>
<a><b>Title 2</b>
	<c></c>
</a>
<a><b>Title 3</b>
	<c>2023</c>
</a>
</ArticleSet>"

x = read_xml(sx)

ns = xml_find_all(x, "/ArticleSet/a")
ns

# one Node is missing the Year
# !! find_all actually skips this node !!
xml_find_all(ns, ".//c/text()")
# nodeset with only 2023 & 2023;
xml_text(xml_find_all(ns, ".//c"))
# "2023" ""     "2023"
xml_find_num(ns, ".//c/text()")
主要言語
R
スター
227
フォーク
86
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

r-lib/xml2 のほかの issue

r-lib/xml2 の issue をすべて見る

似ている issue

R の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。