xml_descendants() as akin to xml_child()/xml_children() and equivalent to xml_find_all(., "descendant::*")

Đang mở
#409 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
45/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
r, xml
Lĩnh vực
api

Hướng nghiên cứu

Start by inspecting the existing xml_child(), xml_children(), and xml_find_all() entry points; the issue does not name an implementation file or test. Done means providing xml_descendants() with the descendant::* behavior shown and making the helper-src.R indentation example work with it.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

feature

Follow-up to #8.

Consider trying to find the minimal indentation of expressions in an R file (using the AST via {xmlparsedata}). I'll use dbplyr/tests/testthat/helper-src.R for illustration:

library(xmlparsedata)
library(xml2)

xml <- "https://raw.githubusercontent.com/tidyverse/dbplyr/1e48cfaf795f9101792567bc68ce7d24a19db9d5/tests/testthat/helper-src.R" |>
 parse() |>
 xml_parse_data() |>
 read_xml()
Objective: comment calls to test_register_con(), besides the RSQLite one, with the correct indentation
xpath <- "
//SYMBOL_FUNCTION_CALL[text() = 'test_register_con']
    /parent::expr
    /parent::expr[not(.//SYMBOL_PACKAGE[text() = 'RSQLite'])]
"

exprs <- xml_find_all(xml, xpath)

The part about indentation requires examining the col1 attribute for all descendant nodes of exprs. Here's how we can do this currently:

col1s <- vapply(
  exprs,
  \(expr) min(as.integer(xml_attr(xml_find_all(expr, ".//*"), "col1"))),
  integer(1L)
)

If we have xml_descendants(), this can be a tad cleaner + more readable:

col1s <- vapply(
  exprs,
  \(expr) min(as.integer(xml_attr(xml_descendants(expr), "col1"))),
  integer(1L)
)
Ngôn ngữ chính
R
Star
227
Fork
86
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của r-lib/xml2

Tất cả issue của r-lib/xml2

Issue tương tự

Thêm issue về R

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.