Skip to content

Commit

Permalink
docs: update roxygen documentation and pkgdown site files
Browse files Browse the repository at this point in the history
  • Loading branch information
davidycliao committed Jan 5, 2025
1 parent 6ad48ba commit 427d08e
Show file tree
Hide file tree
Showing 25 changed files with 150 additions and 65 deletions.
2 changes: 1 addition & 1 deletion .Rproj.user/763C8F27/pcs/source-pane.pper
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"activeTab": 4
"activeTab": 5
}
2 changes: 1 addition & 1 deletion .Rproj.user/763C8F27/pcs/workbench-pane.pper
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"TabSet1": 2,
"TabSet1": 5,
"TabSet2": 1,
"TabZoom": {}
}
6 changes: 3 additions & 3 deletions .Rproj.user/763C8F27/persistent-state

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions .Rproj.user/763C8F27/sources/prop/55451CD2
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"source_window_id": "",
"Source": "Source",
"cursorPosition": "29,0",
"scrollLine": "15"
"cursorPosition": "6,11",
"scrollLine": "0"
}
4 changes: 2 additions & 2 deletions .Rproj.user/763C8F27/sources/prop/70BF7A76
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"source_window_id": "",
"Source": "Source",
"cursorPosition": "8,1",
"scrollLine": "0"
"cursorPosition": "42,3",
"scrollLine": "15"
}
2 changes: 1 addition & 1 deletion .Rproj.user/763C8F27/sources/prop/8DB96273
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"tempName": "Untitled1",
"source_window_id": "",
"Source": "Source",
"cursorPosition": "0,0",
"cursorPosition": "18,47",
"scrollLine": "0"
}
4 changes: 2 additions & 2 deletions .Rproj.user/763C8F27/sources/prop/A6FC25F9
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"source_window_id": "",
"Source": "Source",
"cursorPosition": "27,10",
"scrollLine": "6"
"cursorPosition": "30,9",
"scrollLine": "18"
}
4 changes: 4 additions & 0 deletions .Rproj.user/763C8F27/sources/prop/INDEX
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
~%2FDropbox%2FMy%20Packages%2FlegisTaiwan%2FR%2Fmeeting.R="89BA0F7B"
~%2FDropbox%2FMy%20Packages%2FlegisTaiwan%2FR%2Fparlquestions.R="9DFFCB24"
~%2FDropbox%2FMy%20Packages%2FlegisTaiwan%2FR%2Fstat_tool.R="C8BF0021"
~%2FDropbox%2FMy%20Packages%2FlegisTaiwan%2FR%2Ftest_get_ly_legislator_detail.R="6C2EF5CA"
~%2FDropbox%2FMy%20Packages%2FlegisTaiwan%2FR%2Ftest_get_ly_legislators_by_term.R="963916C8"
~%2FDropbox%2FMy%20Packages%2FlegisTaiwan%2FR%2Ftest_that.R="05D36D8A"
~%2FDropbox%2FMy%20Packages%2FlegisTaiwan%2FR%2Futils.R="6AB6A820"
~%2FDropbox%2FMy%20Packages%2FlegisTaiwan%2FR%2Fvis_tool.R="1585B4F2"
~%2FDropbox%2FMy%20Packages%2FlegisTaiwan%2FR%2Fzzz.R="70BF7A76"
Expand All @@ -44,9 +46,11 @@
~%2FDropbox%2FMy%20Packages%2FlegisTaiwan%2Ftests%2Ftestthat%2Fget_ly_legislator_cosign_bills.R="12F53D0F"
~%2FDropbox%2FMy%20Packages%2FlegisTaiwan%2Ftests%2Ftestthat%2Ftest_bills.R="F2EB84F7"
~%2FDropbox%2FMy%20Packages%2FlegisTaiwan%2Ftests%2Ftestthat%2Ftest_get_infos.R="0D1C8547"
~%2FDropbox%2FMy%20Packages%2FlegisTaiwan%2Ftests%2Ftestthat%2Ftest_get_ly_committees_type.R="D09B9C31"
~%2FDropbox%2FMy%20Packages%2FlegisTaiwan%2Ftests%2Ftestthat%2Ftest_get_ly_interpellations.R="05DA321E"
~%2FDropbox%2FMy%20Packages%2FlegisTaiwan%2Ftests%2Ftestthat%2Ftest_get_ly_ivod.R="5D8DCAD1"
~%2FDropbox%2FMy%20Packages%2FlegisTaiwan%2Ftests%2Ftestthat%2Ftest_get_ly_legislator_bills.R="8FFC86C0"
~%2FDropbox%2FMy%20Packages%2FlegisTaiwan%2Ftests%2Ftestthat%2Ftest_get_ly_legislator_detail.R="9F2F35AB"
~%2FDropbox%2FMy%20Packages%2FlegisTaiwan%2Ftests%2Ftestthat%2Ftest_get_ly_legislators_by_term.R="BD95594E"
~%2FDropbox%2FMy%20Packages%2FlegisTaiwan%2Ftests%2Ftestthat%2Ftest_legislators.R="464CF3FF"
~%2FDropbox%2FMy%20Packages%2FlegisTaiwan%2Ftests%2Ftestthat%2Ftest_meeting.R="2C24CF14"
Expand Down

This file was deleted.

4 changes: 4 additions & 0 deletions .Rproj.user/shared/notebooks/paths
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
/Users/yenchiehliao/Dropbox/My Packages/legisTaiwan/R/meeting.R="71127899"
/Users/yenchiehliao/Dropbox/My Packages/legisTaiwan/R/parlquestions.R="13501FDC"
/Users/yenchiehliao/Dropbox/My Packages/legisTaiwan/R/stat_tool.R="530A04F8"
/Users/yenchiehliao/Dropbox/My Packages/legisTaiwan/R/test_get_ly_legislator_detail.R="1E685BDC"
/Users/yenchiehliao/Dropbox/My Packages/legisTaiwan/R/test_that.R="7C88AFED"
/Users/yenchiehliao/Dropbox/My Packages/legisTaiwan/R/utils.R="7BAFD3F6"
/Users/yenchiehliao/Dropbox/My Packages/legisTaiwan/R/zzz.R="9DA89192"
/Users/yenchiehliao/Dropbox/My Packages/legisTaiwan/README.Rmd="9551FBD9"
Expand All @@ -35,9 +37,11 @@
/Users/yenchiehliao/Dropbox/My Packages/legisTaiwan/tests/testthat/get_ly_legislator_cosign_bills.R="C6AC0678"
/Users/yenchiehliao/Dropbox/My Packages/legisTaiwan/tests/testthat/test_bills.R="2C532035"
/Users/yenchiehliao/Dropbox/My Packages/legisTaiwan/tests/testthat/test_get_infos.R="DC03EE48"
/Users/yenchiehliao/Dropbox/My Packages/legisTaiwan/tests/testthat/test_get_ly_committees_type.R="32A85602"
/Users/yenchiehliao/Dropbox/My Packages/legisTaiwan/tests/testthat/test_get_ly_interpellations.R="D26D9876"
/Users/yenchiehliao/Dropbox/My Packages/legisTaiwan/tests/testthat/test_get_ly_ivod.R="DF77FEF8"
/Users/yenchiehliao/Dropbox/My Packages/legisTaiwan/tests/testthat/test_get_ly_legislator_bills.R="5A9A4607"
/Users/yenchiehliao/Dropbox/My Packages/legisTaiwan/tests/testthat/test_get_ly_legislator_detail.R="7CF584FF"
/Users/yenchiehliao/Dropbox/My Packages/legisTaiwan/tests/testthat/test_get_ly_legislators_by_term.R="FF7E8788"
/Users/yenchiehliao/Dropbox/My Packages/legisTaiwan/tests/testthat/test_legislators.R="290647EE"
/Users/yenchiehliao/Dropbox/My Packages/legisTaiwan/tests/testthat/test_meeting.R="35E091D2"
Expand Down
11 changes: 7 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ Authors@R: c(person("Yen-Chieh", "Liao", email = "davidycliao@gmail.com", role =
person("Taiwan National Science and Technology Council", role = "ctb"),
person("Taiwan Science & Technology Policy Research and Information Center NARLabs", role = "ctb"))
Description: The package is designed to make it quickly and easy to access Taiwan
Legislative Yuan API for downloading real-time data legislative and
historical archives.
Legislative Yuan API for downloading real-time data, legislative records and
historical archives. Features include access to committee meetings,
interpellations, bills, legislator information, parliamentary questions,
and executive responses. The API provides comprehensive coverage of
legislative activities including voting records, meeting minutes, and
policy discussions, enabling users to analyze Taiwan's legislative
processes and parliamentary operations efficiently.
Maintainer: Yen-Chieh Liao <davidycliao@gmail.com>
Depends: R (>= 3.4.0)
License: GPL-3 + file LICENSE
Expand All @@ -24,8 +29,6 @@ Imports:
rvest,
withr,
httr,
pillar,
vctrs,
utils,
readr,
dplyr,
Expand Down
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export(get_public_debates)
export(get_speech_video)
export(get_tly_stat)
export(get_variable_info)
export(type_sum.accel)
import(ggplot2)
import(utils)
importFrom(attempt,stop_if_all)
Expand Down
34 changes: 10 additions & 24 deletions R/zzz.R
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@

#' Register S3 methods and set up package
#' @keywords internal
.onLoad <- function(libname, pkgname) {
# 檢查並註冊 S3 方法
if (requireNamespace("vctrs", quietly = TRUE)) {
vctrs::s3_register("pillar::type_sum", "accel")
}
}


#' On package attach, display a startup message
#'
#' Package startup message
#' @keywords internal
.onAttach <- function(...) {
# ANSI color codes
Expand All @@ -36,23 +24,21 @@
)

# Creating the messages
base_message1 <- paste0(dark_green, "legis", reset, rainbow_taiwan, " v0.2.1")
version <- utils::packageVersion("legisTaiwan")
base_message1 <- paste0(dark_green, "legis", reset, rainbow_taiwan, " v", version)
message2 <- "## An R package connecting to the Taiwan Legislative API. ##"

# Calculate padding to align message1 with message2
message2_width <- nchar(message2)
base_message1_width <- nchar(base_message1) - (6 * 9) # Subtract length of color codes (9 codes * 6 characters)
padding_needed <- message2_width - base_message1_width - 1 # -4 for the "## " and " ##"
base_message1_width <- nchar(base_message1) - (6 * 9) # Subtract length of color codes
padding_needed <- message2_width - base_message1_width - 1

# Create aligned message1
message1 <- paste0("## ", base_message1, paste(rep(" ", padding_needed), collapse = ""), " ##")

# Display messages
packageStartupMessage(message1)
packageStartupMessage(message2)
}

#' @export
type_sum.accel <- function(x) {
"accel"
# Display messages if not disabled
if (!isFALSE(getOption("legisTaiwan.startup.message", TRUE))) {
packageStartupMessage(message1)
packageStartupMessage(message2)
}
}
2 changes: 1 addition & 1 deletion docs/pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pkgdown: 2.1.1
pkgdown_sha: ~
articles:
quickstart: quickstart.html
last_built: 2025-01-05T00:41Z
last_built: 2025-01-05T00:44Z
urls:
reference: https://davidycliao.github.io/legisTaiwan/reference
article: https://davidycliao.github.io/legisTaiwan/articles
2 changes: 1 addition & 1 deletion docs/reference/get_caucus_meetings.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/get_executive_response.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/get_legislators.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions docs/reference/get_meetings.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions docs/reference/get_parlquestions.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/search.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/sitemap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<url><loc>https://davidycliao.github.io/legisTaiwan/reference/create_interactive_plot.html</loc></url>
<url><loc>https://davidycliao.github.io/legisTaiwan/reference/dot-clean_names.html</loc></url>
<url><loc>https://davidycliao.github.io/legisTaiwan/reference/dot-onAttach.html</loc></url>
<url><loc>https://davidycliao.github.io/legisTaiwan/reference/dot-onLoad.html</loc></url>
<url><loc>https://davidycliao.github.io/legisTaiwan/reference/generate_report.html</loc></url>
<url><loc>https://davidycliao.github.io/legisTaiwan/reference/get_bills.html</loc></url>
<url><loc>https://davidycliao.github.io/legisTaiwan/reference/get_bills_2.html</loc></url>
Expand Down
4 changes: 2 additions & 2 deletions man/dot-onAttach.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 0 additions & 12 deletions man/dot-onLoad.Rd

This file was deleted.

38 changes: 38 additions & 0 deletions tests/testthat/test_get_ly_committees_type.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
test_that("get_ly_committees_type basic functionality", {
# 測試基本呼叫
result <- get_ly_committees_type(show_progress = FALSE)

# 檢查回傳值結構
expect_type(result, "list")

# 檢查資料框結構
expect_s3_class(result$committees, "data.frame")
expect_named(result$committees, c("代號", "名稱", "職掌", "類別"))
})

test_that("get_ly_committees_type handles parameters correctly", {
# 測試特定參數
result <- get_ly_committees_type(
page = 1,
per_page = 10,
type = "常設委員會",
show_progress = FALSE
)

# 檢查分頁設定
expect_equal(result$metadata$current_page, 1)
expect_equal(result$metadata$per_page, 100)

# 檢查委員會類別
if(nrow(result$committees) > 0) {
expect_equal(unique(result$committees$類別), "常設委員會")
}
})

test_that("get_ly_committees_type error handling", {
# 測試錯誤參數
expect_error(
get_ly_committees_type(page = "invalid", show_progress = FALSE),
"API request failed with status code: 500"
)
})
63 changes: 63 additions & 0 deletions tests/testthat/test_get_ly_legislator_detail.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
test_that("parameter validation works", {
# 測試缺少必要參數
expect_error(
get_ly_legislator_detail(name = "王金平", show_progress = FALSE),
"term parameter is required"
)

expect_error(
get_ly_legislator_detail(term = 9, show_progress = FALSE),
"name parameter is required"
)

# 測試參數型別錯誤
expect_error(
get_ly_legislator_detail(term = "9", name = "王金平", show_progress = FALSE),
"term must be numeric"
)

expect_error(
get_ly_legislator_detail(term = 9, name = 123, show_progress = FALSE),
"name must be character"
)
})

test_that("basic functionality works", {
# 測試基本功能
result <- get_ly_legislator_detail(
term = 9,
name = "王金平",
show_progress = FALSE
)

# 檢查回傳值結構
expect_type(result, "list")

# 檢查必要欄位
expected_fields <- c(
"term", "name", "party",
"areaName", "partyGroup"
)

for(field in expected_fields) {
expect_true(
field %in% names(result),
info = sprintf("Field '%s' should exist in result", field)
)
}

# 檢查資料內容
expect_equal(result$term, 9)
expect_equal(result$name, "王金平")
})

test_that("invalid term/name combination returns error", {
expect_error(
get_ly_legislator_detail(
term = 999,
name = "不存在的立委",
show_progress = FALSE
),
"API request failed with status code: "
)
})

0 comments on commit 427d08e

Please sign in to comment.