From 87ba2e414564ec2b437d186049fbdc64746b5266 Mon Sep 17 00:00:00 2001 From: davidycliao Date: Sun, 19 Jan 2025 22:36:31 +0000 Subject: [PATCH] docs: update API migration notice and package description docs: update API migration notice and package description - Update README.Rmd with clearer TheyWorkForYou API reference - Revise API migration notice wording - Update documentation formatting and style --- .Rhistory | 908 +++++++++--------- .Rproj.user/763C8F27/pcs/source-pane.pper | 2 +- .../763C8F27/pcs/windowlayoutstate.pper | 12 +- .Rproj.user/763C8F27/pcs/workbench-pane.pper | 2 +- .Rproj.user/763C8F27/persistent-state | 2 +- .Rproj.user/763C8F27/rmd-outputs | 2 +- .Rproj.user/763C8F27/sources/per/t/115577B3 | 27 - .../763C8F27/sources/per/t/115577B3-contents | 200 ---- .Rproj.user/763C8F27/sources/per/t/2949E748 | 28 - .../763C8F27/sources/per/t/2949E748-contents | 133 --- .Rproj.user/763C8F27/sources/per/t/4152F724 | 26 - .../763C8F27/sources/per/t/4152F724-contents | 204 ---- .Rproj.user/763C8F27/sources/per/t/461AEA8B | 27 - .../763C8F27/sources/per/t/461AEA8B-contents | 89 -- .Rproj.user/763C8F27/sources/per/t/53011D1D | 26 - .../763C8F27/sources/per/t/53011D1D-contents | 55 -- .Rproj.user/763C8F27/sources/per/t/92AB474C | 29 - .../763C8F27/sources/per/t/92AB474C-contents | 132 --- .Rproj.user/763C8F27/sources/per/t/AE90ACEE | 26 - .../763C8F27/sources/per/t/AE90ACEE-contents | 141 --- .Rproj.user/763C8F27/sources/per/t/C9ACA1E1 | 26 - .../763C8F27/sources/per/t/C9ACA1E1-contents | 115 --- .Rproj.user/763C8F27/sources/per/t/E6CE64AC | 26 - .Rproj.user/763C8F27/sources/prop/023A30B2 | 2 +- .Rproj.user/763C8F27/sources/prop/15233BD7 | 4 +- .Rproj.user/763C8F27/sources/prop/55451CD2 | 4 +- .Rproj.user/763C8F27/sources/prop/5CAD1E2F | 4 +- .Rproj.user/763C8F27/sources/prop/6AB6A820 | 2 +- .Rproj.user/763C8F27/sources/prop/7436917F | 4 +- .Rproj.user/763C8F27/sources/prop/777CDD25 | 4 +- .Rproj.user/763C8F27/sources/prop/7A33FC4C | 4 +- .Rproj.user/763C8F27/sources/prop/884D4207 | 4 +- .Rproj.user/763C8F27/sources/prop/89BA0F7B | 4 +- .Rproj.user/763C8F27/sources/prop/8DB96273 | 2 +- .Rproj.user/763C8F27/sources/prop/9DFFCB24 | 4 +- .Rproj.user/763C8F27/sources/prop/BBA15AFC | 4 +- .Rproj.user/763C8F27/sources/prop/BD0F88A4 | 4 +- .Rproj.user/763C8F27/sources/prop/C3758EE8 | 4 +- .Rproj.user/763C8F27/sources/prop/C5FFA97C | 2 +- .Rproj.user/763C8F27/sources/prop/C7EAE541 | 7 +- .Rproj.user/763C8F27/sources/prop/CD7A53F9 | 4 +- .Rproj.user/763C8F27/sources/prop/D4DABFE1 | 2 +- .Rproj.user/763C8F27/sources/prop/DFE1904A | 4 +- .Rproj.user/763C8F27/sources/prop/F2CB7519 | 4 +- .Rproj.user/763C8F27/sources/prop/FE4518BA | 4 +- .../sources/session-61743cf2/A0507168 | 26 - .../sources/session-61743cf2/B9596C53 | 26 - .../session-61743cf2/B9596C53-contents | 16 - .../sources/session-61743cf2/lock_file | 0 .../session-fadbc9d6/197052BE-contents | 9 - .../session-fadbc9d6/BC739EBB-contents | 250 ----- .../sources/session-fadbc9d6/lock_file | 0 .../5E338CCA-quickstart/1/s/chunks.json | 2 +- .../notebooks/9551FBD9-README/1/s/chunks.json | 2 +- NEWS.md | 8 +- R/data.R | 2 +- R/get_ly_bills.R | 2 +- R/get_ly_committees.R | 2 +- R/get_ly_committees_type.R | 2 +- R/get_ly_interpellations.R | 2 +- R/get_ly_ivod.R | 3 +- R/get_ly_legislator_bills.R | 3 +- R/get_ly_legislator_cosign_bills.R | 4 +- R/get_ly_legislator_detail.R | 2 +- R/get_ly_legislators_by_term.R | 2 +- R/get_ly_stat.R | 2 +- R/info.R | 83 +- R/legislators.R | 18 +- R/meeting.R | 52 +- R/parlquestions.R | 34 +- R/utils.R | 2 - README.Rmd | 22 +- README.md | 127 ++- _pkgdown.yml | 82 +- docs/404.html | 14 +- docs/LICENSE-text.html | 12 +- docs/articles/index.html | 12 +- docs/articles/quickstart.html | 70 +- docs/authors.html | 12 +- docs/index.html | 14 +- docs/news/index.html | 18 +- docs/pkgdown.yml | 2 +- docs/reference/analyze_bills.html | 12 +- docs/reference/analyze_ivod.html | 12 +- docs/reference/analyze_meetings.html | 12 +- docs/reference/api_check.html | 12 +- docs/reference/calculate_bill_trends.html | 12 +- docs/reference/check_date.html | 12 +- docs/reference/check_date2.html | 12 +- docs/reference/check_internet.html | 12 +- docs/reference/dot-clean_names.html | 12 +- docs/reference/dot-onAttach.html | 12 +- docs/reference/generate_report.html | 12 +- docs/reference/get_bills.html | 12 +- docs/reference/get_bills_2.html | 12 +- docs/reference/get_caucus_meetings.html | 23 +- docs/reference/get_committee_record.html | 12 +- docs/reference/get_executive_response.html | 27 +- docs/reference/get_legislators.html | 104 +- docs/reference/get_ly_bills.html | 22 +- docs/reference/get_ly_committee_meets.html | 16 +- docs/reference/get_ly_committees_type.html | 16 +- docs/reference/get_ly_interpellations.html | 16 +- docs/reference/get_ly_ivod.html | 23 +- docs/reference/get_ly_legislator_bills.html | 20 +- .../get_ly_legislator_cosign_bills.html | 18 +- docs/reference/get_ly_legislator_detail.html | 14 +- .../reference/get_ly_legislators_by_term.html | 16 +- docs/reference/get_meetings.html | 25 +- docs/reference/get_parlquestions.html | 112 +-- docs/reference/get_public_debates.html | 12 +- docs/reference/get_speech_video.html | 15 +- docs/reference/get_tly_stat.html | 16 +- docs/reference/get_variable_info.html | 49 +- docs/reference/index.html | 168 +++- docs/reference/legis_keywords.html | 14 +- docs/reference/review_session_info.html | 22 +- docs/reference/transformed_date_bill.html | 12 +- docs/reference/transformed_date_meeting.html | 12 +- docs/reference/validate_dates_format.html | 12 +- docs/reference/website_availability.html | 12 +- docs/reference/website_availability2.html | 12 +- docs/search.json | 2 +- legisTaiwan.Rproj | 1 + man/figures/unnamed-chunk-4-1.png | Bin 0 -> 33136 bytes man/figures/unnamed-chunk-5-1.png | Bin 0 -> 22683 bytes man/figures/unnamed-chunk-6-1.png | Bin 0 -> 20869 bytes man/get_caucus_meetings.Rd | 5 +- man/get_executive_response.Rd | 9 +- man/get_legislators.Rd | 13 +- man/get_ly_bills.Rd | 2 +- man/get_ly_committee_meets.Rd | 2 +- man/get_ly_committees_type.Rd | 2 +- man/get_ly_interpellations.Rd | 2 +- man/get_ly_ivod.Rd | 3 +- man/get_ly_legislator_bills.Rd | 5 +- man/get_ly_legislator_cosign_bills.Rd | 4 +- man/get_ly_legislator_detail.Rd | 2 +- man/get_ly_legislators_by_term.Rd | 2 +- man/get_meetings.Rd | 5 +- man/get_parlquestions.Rd | 14 +- man/get_speech_video.Rd | 2 - man/get_tly_stat.Rd | 2 +- man/get_variable_info.Rd | 11 +- man/legis_keywords.Rd | 2 +- man/review_session_info.Rd | 7 +- vignettes/quickstart.Rmd | 36 +- vignettes/quickstart.html | 66 +- 148 files changed, 1679 insertions(+), 2754 deletions(-) delete mode 100644 .Rproj.user/763C8F27/sources/per/t/115577B3 delete mode 100644 .Rproj.user/763C8F27/sources/per/t/115577B3-contents delete mode 100644 .Rproj.user/763C8F27/sources/per/t/2949E748 delete mode 100644 .Rproj.user/763C8F27/sources/per/t/2949E748-contents delete mode 100644 .Rproj.user/763C8F27/sources/per/t/4152F724 delete mode 100644 .Rproj.user/763C8F27/sources/per/t/4152F724-contents delete mode 100644 .Rproj.user/763C8F27/sources/per/t/461AEA8B delete mode 100644 .Rproj.user/763C8F27/sources/per/t/461AEA8B-contents delete mode 100644 .Rproj.user/763C8F27/sources/per/t/53011D1D delete mode 100644 .Rproj.user/763C8F27/sources/per/t/53011D1D-contents delete mode 100644 .Rproj.user/763C8F27/sources/per/t/92AB474C delete mode 100644 .Rproj.user/763C8F27/sources/per/t/92AB474C-contents delete mode 100644 .Rproj.user/763C8F27/sources/per/t/AE90ACEE delete mode 100644 .Rproj.user/763C8F27/sources/per/t/AE90ACEE-contents delete mode 100644 .Rproj.user/763C8F27/sources/per/t/C9ACA1E1 delete mode 100644 .Rproj.user/763C8F27/sources/per/t/C9ACA1E1-contents delete mode 100644 .Rproj.user/763C8F27/sources/per/t/E6CE64AC delete mode 100644 .Rproj.user/763C8F27/sources/session-61743cf2/A0507168 delete mode 100644 .Rproj.user/763C8F27/sources/session-61743cf2/B9596C53 delete mode 100644 .Rproj.user/763C8F27/sources/session-61743cf2/B9596C53-contents delete mode 100644 .Rproj.user/763C8F27/sources/session-61743cf2/lock_file delete mode 100644 .Rproj.user/763C8F27/sources/session-fadbc9d6/197052BE-contents delete mode 100644 .Rproj.user/763C8F27/sources/session-fadbc9d6/BC739EBB-contents delete mode 100644 .Rproj.user/763C8F27/sources/session-fadbc9d6/lock_file create mode 100644 man/figures/unnamed-chunk-4-1.png create mode 100644 man/figures/unnamed-chunk-5-1.png create mode 100644 man/figures/unnamed-chunk-6-1.png diff --git a/.Rhistory b/.Rhistory index f6365ece..15992823 100644 --- a/.Rhistory +++ b/.Rhistory @@ -1,512 +1,512 @@ -test_that("get_ly_legislator_bills handles errors properly", { -# Test non-existent term/name combination +mock_resp <- structure( +list( +status_code = 200, +content = charToRaw(mock_json) +), +class = "response" +) +# Mock httr::GET +mockery::stub(get_ly_committee_meets, "httr::GET", mock_resp) +# Test the function +result <- get_ly_committee_meets(committee_id = 1, show_progress = FALSE) +# Check structure +expect_type(result, "list") +expect_named(result, c("metadata", "meetings")) +# Check metadata +expect_equal(result$metadata$total, 1) +expect_equal(result$metadata$total_page, 1) +expect_equal(result$metadata$current_page, 1) +expect_equal(result$metadata$per_page, 20) +# Check meetings data +expect_s3_class(result$meetings, "data.frame") +expect_equal(nrow(result$meetings), 1) +expect_equal(result$meetings$會議名稱[1], "測試委員會") +expect_equal(result$meetings$會議代碼[1], "TEST001") +expect_equal(result$meetings$地點[1], "立法院紅樓") +}) +expect_error(get_ly_committee_meets(), "committee_id is required") +expect_error(get_ly_committee_meets("abc"), "committee_id must be numeric") +test_that("get_ly_committee_meets handles input validation", { +expect_error(get_ly_committee_meets(), "committee_id is required") +expect_error(get_ly_committee_meets("abc"), "committee_id must be numeric") +}) +test_that("get_ly_committee_meets handles API errors", { +# Mock error response +mock_error_resp <- structure( +list(status_code = 404), +class = "response" +) +mockery::stub(get_ly_committee_meets, "httr::GET", mock_error_resp) expect_error( -get_ly_legislator_bills( -term = 999, -name = "不存在的立委" +get_ly_committee_meets(committee_id = 1, show_progress = FALSE), +"API request failed with status code: 404" ) +}) +test_that("get_ly_committee_meets handles API errors", { +# Mock error response +mock_error_resp <- structure( +list(status_code = 404), +class = "response" ) -# Test invalid page number +mockery::stub(get_ly_committee_meets, "httr::GET", mock_error_resp) expect_error( -get_ly_legislator_bills( -term = 9, -name = "王金平", -page = -1 +get_ly_committee_meets(committee_id = 1, show_progress = FALSE), +"API request failed with status code: 404" ) +}) +roxygen2::roxygenize() +test_that("get_ly_committee_meets handles input validation", { +expect_error(get_ly_committee_meets(), "committee_id is required") +expect_error(get_ly_committee_meets("abc"), "committee_id must be numeric") +}) +}) +roxygen2::roxygenise() +roxygen2::roxygenise() +library(package) +library(pkgdown) +build_site() +bills <- get_ly_bills( +bill_type = "行政命令(層級)", +show_progress = TRUE +) +get_ly_committee_meets +??get_ly_committee_meets +roxygen2::roxygenize() +get_ly_committee_meets +build_site() +deploy_to_branch() +build_site() +roxygen2::roxygenize() +roxygen2::roxygenize() +build_site() +build_site() +pkgdown::preview_site(path='reference/get_caucus_meetings.html') +pkgdown::preview_site(path='reference/get_caucus_meetings.html') +roxygen2::roxygenize() +roxygen2::roxygenize() +roxygen2::roxygenize() +# 測試基本呼叫 +result <- get_ly_committees_type(show_progress = FALSE) +# 測試基本呼叫 +result <- get_ly_committees_type(show_progress = FALSE) +library(legisTaiwan) +# 測試基本呼叫 +result <- get_ly_committees_type(show_progress = FALSE) +# 檢查回傳值結構 +expect_type(result, "list") +library(testtha) +library(testthat) +# 檢查回傳值結構 +expect_type(result, "list") +texpect_named(result, c("metadata", "committees")) +texpect_named +# 檢查資料框結構 +expect_s3_class(result$committees, "data.frame") +# 檢查資料框結構 +expect_s3_class(result$committees, "data.frame") +expect_named(result$committees, c("代號", "名稱", "職掌", "類別")) +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, 10) +# 檢查委員會類別 +if(nrow(result$committees) > 0) { +expect_equal(unique(result$committees$類別), "常設委員會") +} +}) +# 測試特定參數 +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, 10) +esult$metadata$per_page +result$metadata$per_page +expect_equal(result$metadata$per_page, 100) +# 檢查委員會類別 +if(nrow(result$committees) > 0) { +expect_equal(unique(result$committees$類別), "常設委員會") +} +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$類別), "常設委員會") +} +}) +utils::packageVersion("legisTaiwan") +if(nrow(result$committees) > 0) { +expect_equal(unique(result$committees$類別), "常設委員會") +} +test_that("get_ly_committees_type handles parameters correctly", { +# 測試特定參數 +result <- get_ly_committees_type( +page = 1, +per_page = 10, +type = "常設委員會", +show_progress = FALSE ) -# Test invalid limit +# 檢查分頁設定 +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_legislator_bills( -term = 9, -name = "王金平", -limit = 0 +get_ly_committees_type(page = "invalid"), +"page" ) +expect_error( +get_ly_committees_type(per_page = -1), +"per_page" ) }) -# Test error handling -test_that("get_ly_legislator_bills handles errors properly", { -# Test non-existent term/name combination +# 測試錯誤參數 expect_error( -get_ly_legislator_bills( -term = 999, -name = "不存在的立委" +get_ly_committees_type(page = "invalid"), +"page" ) +expect_error( +get_ly_committees_type(per_page = -1), +"per_page" ) -# Test invalid page number +if(nrow(result$committees) > 0) { +expect_equal(unique(result$committees$類別), "常設委員會") +} +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_legislator_bills( -term = 9, -name = "王金平", -page = -1 +get_ly_committees_type(page = "invalid"), +"page" ) +}) +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$類別), "常設委員會") +} }) -get_tly_stat() -library(legisTaiwan) -ly_info <- get_tly_stat() -library(legisTaiwan) -ly_info <- get_tly_stat() -ly_info -ly_info$meet$terms -print(ly_info$meet$terms, type = "html") -ly_info$bill$total -ly_info$bill -ly_info$bill$terms -ly_info$legislator$terms -ly_info$gazette$yearly_stats -ly_info$gazette$agenda_total -ly_info$meet$terms -ly_info$ivod$terms -ly_info$bill$terms -ly_info$meet$total -get_tly_stat() -roxygen2::roxygenise() -roxygen2::roxygenise() -roxygen2::roxygenise() -committees <- get_ly_committees_type( -type = "常設委員會" +expect_error( +get_ly_committees_type(page = "invalid"), +"page" ) -committee <- get_ly_committees_type( -code = 15 +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" ) -committee -committee <- get_ly_committees_type( +expect_error( +get_ly_committees_type(per_page = -1, show_progress = FALSE), +"API request failed with status code: 500" ) -roxygen2::roxygenise() -esult <- get_ly_committee_meets(committee_id = 22) -roxygen2::roxygenise() -esult <- get_ly_committee_meets(committee_id = 22) -page2_videos <- get_ly_ivod( -term = 9, -session_period = 1, -page = 2, -limit = 20 +}) +expect_error( +get_ly_committees_type(page = "invalid", show_progress = FALSE), +"API request failed with status code: 500" ) -roxygen2::roxygenise() -esult <- get_ly_committee_meets(committee_id = 22) -# 取得第九屆第一會期的影片 -videos <- get_ly_ivod( +expect_error( +get_ly_committees_type(per_page = -1, show_progress = FALSE), +"API request failed with status code: 500" +) +expect_error( +get_ly_legislator_detail(term = 9, name = 123, show_progress = FALSE), +"name must be character" +) +# 測試缺少必要參數 +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("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" +) +}) +# 測試基本功能 +result <- get_ly_legislator_detail( term = 9, -session_period = 1, -limit = 5 +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) ) -roxygen2::roxygenise() -roxygen2::roxygenise() -roxygen2::roxygenise() -file.edit("~/.Rprofile") -roxygen2::roxygenise() -stats <- get_tly_stat() -# 案例一:基本統計資訊分析 -library(dplyr) -library(ggplot2) -# 取得立法院統計資料 -stats <- get_tly_stat() -# 1. 分析各屆期法案統計 -analyze_bills <- function(stats) { -# 計算各屆期法案數量和比例 -bill_stats <- stats$bill$terms %>% -mutate( -percentage = round(count / sum(count) * 100, 2), -cumulative = cumsum(count) -) -# 繪製法案數量趨勢圖 -ggplot(bill_stats, aes(x = term, y = count)) + -geom_line(color = "blue") + -geom_point(color = "red") + -labs( -title = "各屆期法案數量趨勢", -x = "屆期", -y = "法案數量" -) + -theme_minimal() -# 輸出統計摘要 -cat("\n=== 法案統計摘要 ===\n") -cat(sprintf("總法案數:%d\n", stats$bill$total)) -cat(sprintf("最後更新時間:%s\n", format(stats$bill$max_update_time))) -cat("\n前五屆法案數量:\n") -print(head(bill_stats, 5)) -} -# 2. 分析會議資訊 -analyze_meetings <- function(stats) { -# 整理會議資料 -meeting_stats <- stats$meet$terms %>% -mutate( -議事錄比例 = round(議事錄_count / count * 100, 2), -最後會議日期 = format(max_meeting_date, "%Y-%m-%d") -) -# 繪製會議記錄完整性分析圖 -ggplot(meeting_stats, aes(x = term)) + -geom_bar(aes(y = count), stat = "identity", fill = "blue", alpha = 0.5) + -geom_bar(aes(y = 議事錄_count), stat = "identity", fill = "red", alpha = 0.5) + -labs( -title = "各屆期會議記錄完整性分析", -x = "屆期", -y = "數量" -) + -theme_minimal() -# 輸出統計摘要 -cat("\n=== 會議統計摘要 ===\n") -cat(sprintf("總會議數:%d\n", stats$meet$total)) -cat("\n各屆期會議記錄統計:\n") -print(head(meeting_stats, 5)) -} -# 3. 分析影片資料 -analyze_ivod <- function(stats) { -# 整理影片資料 -ivod_stats <- stats$ivod$terms %>% -mutate( -開始日期 = format(start_date, "%Y-%m-%d"), -結束日期 = format(end_date, "%Y-%m-%d"), -期間天數 = as.numeric(difftime(end_date, start_date, units = "days")), -平均每日影片數 = round(count / 期間天數, 2) -) -# 繪製影片數量分布圖 -ggplot(ivod_stats, aes(x = term, y = count)) + -geom_bar(stat = "identity", fill = "darkgreen") + -labs( -title = "各屆期影片記錄數量", -x = "屆期", -y = "影片數量" -) + -theme_minimal() -# 輸出統計摘要 -cat("\n=== 影片統計摘要 ===\n") -cat(sprintf("總影片數:%d\n", stats$ivod$total)) -cat(sprintf("資料期間:%s 至 %s\n", -format(stats$ivod$date_range$start, "%Y-%m-%d"), -format(stats$ivod$date_range$end, "%Y-%m-%d"))) -cat("\n各屆期影片統計:\n") -print(head(ivod_stats, 5)) -} -# 4. 整合分析報告 -generate_report <- function(stats) { -cat("\n==========================================") -cat("\n 立法院資料統計分析報告") -cat("\n==========================================\n") -# 1. 法案統計 -cat("\nI. 法案統計") -cat("\n------------------------------------------") -cat(sprintf("\n總法案數:%d", stats$bill$total)) -cat(sprintf("\n最新法案更新:%s", format(stats$bill$max_update_time, "%Y-%m-%d"))) -# 2. 委員統計 -cat("\n\nII. 委員統計") -cat("\n------------------------------------------") -cat(sprintf("\n歷史委員總數:%d", stats$legislator$total)) -cat("\n各屆期委員人數:") -print(head(stats$legislator$terms, 5)) -# 3. 公報統計 -cat("\nIII. 公報統計") -cat("\n------------------------------------------") -cat(sprintf("\n公報總數:%d", stats$gazette$total)) -cat(sprintf("\n議程總數:%d", stats$gazette$agenda_total)) -cat(sprintf("\n最後會議日期:%s", format(stats$gazette$last_meeting, "%Y-%m-%d"))) -# 4. 影片統計 -cat("\n\nIV. 影片統計") -cat("\n------------------------------------------") -cat(sprintf("\n影片總數:%d", stats$ivod$total)) -cat(sprintf("\n影片記錄期間:%s 至 %s", -format(stats$ivod$date_range$start, "%Y-%m-%d"), -format(stats$ivod$date_range$end, "%Y-%m-%d"))) -cat("\n\n==========================================\n") -} -# 使用範例: -# 1. 執行基本分析 -stats <- get_tly_stat() -analyze_bills(stats) -analyze_meetings(stats) -analyze_ivod(stats) -# 2. 產生完整報告 -generate_report(stats) -# 3. 特定分析:計算每屆期的法案通過率趨勢 -calculate_bill_trends <- function(stats) { -bill_trends <- stats$bill$terms %>% -left_join(stats$meet$terms, by = "term") %>% -mutate( -bills_per_meeting = round(count.x / count.y, 2), -bills_per_day = round(count.x / as.numeric(difftime(max_meeting_date, -lag(max_meeting_date), units = "days")), 2) -) %>% -select(term, count.x, count.y, bills_per_meeting, bills_per_day) %>% -rename( -bills = count.x, -meetings = count.y -) -print(bill_trends) -return(bill_trends) -} -# 4. 繪製互動式視覺化(需要安裝 plotly 套件) -library(plotly) -create_interactive_plot <- function(stats) { -bill_data <- stats$bill$terms -p <- plot_ly(bill_data, x = ~term, y = ~count, type = "scatter", mode = "lines+markers", -text = ~paste("屆期:", term, "
法案數:", count), -hoverinfo = "text") %>% -layout(title = "各屆期法案數量趨勢", -xaxis = list(title = "屆期"), -yaxis = list(title = "法案數量")) -return(p) -} -install.packages(c("dplyr", "ggplot2", "plotly", "lubridate")) -stats <- get_tly_stat() -analyze_bills(stats) -analyze_meetings(stats) -analyze_ivod(stats) -analyze_ivod(stats) -analyze_meetings(stats) -calculate_bill_trends <- function(stats) { -bill_trends <- stats$bill$terms %>% -left_join(stats$meet$terms, by = "term") %>% -mutate( -bills_per_meeting = round(count.x / count.y, 2), -bills_per_day = round(count.x / as.numeric(difftime(max_meeting_date, -lag(max_meeting_date), units = "days")), 2) -) %>% -select(term, count.x, count.y, bills_per_meeting, bills_per_day) %>% -rename( -bills = count.x, -meetings = count.y -) -print(bill_trends) -return(bill_trends) -} -calculate_bill_trends() -calculate_bill_trends(stats) -create_interactive_plot(stats ) -calculate_bill_trends(stats) -stats -# 2. Meeting information analysis -analyze_meetings <- function(stats) { -# Process meeting data -meeting_stats <- stats$meet$terms %>% -mutate( -minutes_ratio = round(議事錄_count / count * 100, 2), -last_meeting_date = format(max_meeting_date, "%Y-%m-%d") -) -# Create meeting records completeness analysis plot -ggplot(meeting_stats, aes(x = term)) + -geom_bar(aes(y = count), stat = "identity", fill = "blue", alpha = 0.5) + -geom_bar(aes(y = 議事錄_count), stat = "identity", fill = "red", alpha = 0.5) + -labs( -title = "Meeting Records Completeness by Term", -x = "Term", -y = "Count" -) + -theme_minimal() -# Output statistical summary -cat("\n=== Meeting Statistics Summary ===\n") -cat(sprintf("Total Meetings: %d\n", stats$meet$total)) -cat("\nMeeting Records Statistics by Term:\n") -print(head(meeting_stats, 5)) } -# 3. Video data analysis -analyze_ivod <- function(stats) { -# Process video data -ivod_stats <- stats$ivod$terms %>% -mutate( -start_date_fmt = format(start_date, "%Y-%m-%d"), -end_date_fmt = format(end_date, "%Y-%m-%d"), -period_days = as.numeric(difftime(end_date, start_date, units = "days")), -avg_daily_videos = round(count / period_days, 2) -) -# Create video count distribution plot -ggplot(ivod_stats, aes(x = term, y = count)) + -geom_bar(stat = "identity", fill = "darkgreen") + -labs( -title = "Video Records Count by Term", -x = "Term", -y = "Number of Videos" -) + -theme_minimal() -# Output statistical summary -cat("\n=== Video Statistics Summary ===\n") -cat(sprintf("Total Videos: %d\n", stats$ivod$total)) -cat(sprintf("Data Period: %s to %s\n", -format(stats$ivod$date_range$start, "%Y-%m-%d"), -format(stats$ivod$date_range$end, "%Y-%m-%d"))) -cat("\nVideo Statistics by Term:\n") -print(head(ivod_stats, 5)) +# 檢查資料內容 +expect_equal(result$term, 9) +expect_equal(result$name, "王金平") +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) +) } -# 4. Integrated analysis report -generate_report <- function(stats) { -cat("\n==========================================") -cat("\n Legislative Yuan Data Analysis Report") -cat("\n==========================================\n") -# 1. Bill statistics -cat("\nI. Bill Statistics") -cat("\n------------------------------------------") -cat(sprintf("\nTotal Bills: %d", stats$bill$total)) -cat(sprintf("\nLast Bill Update: %s", format(stats$bill$max_update_time, "%Y-%m-%d"))) -# 2. Legislator statistics -cat("\n\nII. Legislator Statistics") -cat("\n------------------------------------------") -cat(sprintf("\nHistorical Total Legislators: %d", stats$legislator$total)) -cat("\nLegislators by Term:") -print(head(stats$legislator$terms, 5)) -# 3. Gazette statistics -cat("\nIII. Gazette Statistics") -cat("\n------------------------------------------") -cat(sprintf("\nTotal Gazettes: %d", stats$gazette$total)) -cat(sprintf("\nTotal Agendas: %d", stats$gazette$agenda_total)) -cat(sprintf("\nLast Meeting Date: %s", format(stats$gazette$last_meeting, "%Y-%m-%d"))) -# 4. Video statistics -cat("\n\nIV. Video Statistics") -cat("\n------------------------------------------") -cat(sprintf("\nTotal Videos: %d", stats$ivod$total)) -cat(sprintf("\nVideo Recording Period: %s to %s", -format(stats$ivod$date_range$start, "%Y-%m-%d"), -format(stats$ivod$date_range$end, "%Y-%m-%d"))) -cat("\n\n==========================================\n") +# 檢查資料內容 +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: " +) +}) +library(legisTaiwan) +library(testthat) +library(testthat) +build_site() +library(pkgdown) +build_site() +# 在你的套件目錄下執行 +tools::dependsOnPkgs("legisTaiwan") +devtools::check_man() # 檢查文件 +devtools::check() # 完整檢查 +readLines("NAMESPACE") +# 在 R console 中執行 +files <- list.files(pattern = "\\.R$", path = "R", full.names = TRUE, recursive = TRUE) +for(file in files) { +lines <- readLines(file) +matches <- grep("accel|type_sum", lines, value = TRUE) +if(length(matches) > 0) { +cat("\nFile:", file, "\n") +print(matches) } -# 2. Meeting information analysis -analyze_meetings <- function(stats) { -# Process meeting data -meeting_stats <- stats$meet$terms %>% -mutate( -minutes_ratio = round(議事錄_count / count * 100, 2), -last_meeting_date = format(max_meeting_date, "%Y-%m-%d") -) -# Create meeting records completeness analysis plot -ggplot(meeting_stats, aes(x = term)) + -geom_bar(aes(y = count), stat = "identity", fill = "blue", alpha = 0.5) + -geom_bar(aes(y = 議事錄_count), stat = "identity", fill = "red", alpha = 0.5) + -labs( -title = "Meeting Records Completeness by Term", -x = "Term", -y = "Count" -) + -theme_minimal() -# Output statistical summary -cat("\n=== Meeting Statistics Summary ===\n") -cat(sprintf("Total Meetings: %d\n", stats$meet$total)) -cat("\nMeeting Records Statistics by Term:\n") -print(head(meeting_stats, 5)) } -analyze_meetings(stats) -# Process meeting data -meeting_stats <- stats$meet$terms %>% -mutate( -minutes_ratio = round(議事錄_count / count * 100, 2), -last_meeting_date = format(max_meeting_date, "%Y-%m-%d") -) -meeting_stats -ggplot(meeting_stats, aes(x = term)) + -geom_bar(aes(y = count), stat = "identity", fill = "blue", alpha = 0.5) + -geom_bar(aes(y = 議事錄_count), stat = "identity", fill = "red", alpha = 0.5) + -labs( -title = "Meeting Records Completeness by Term", -x = "Term", -y = "Count" -) + -theme_minimal() -ggplot(meeting_stats, aes(x = term)) + -geom_bar(aes(y = count), stat = "identity", fill = "blue", alpha = 0.5) -# Create meeting records completeness analysis plot -ggplot(meeting_stats, aes(x = term)) + -geom_bar(aes(y = count), stat = "identity", fill = "blue", alpha = 0.5) + -geom_bar(aes(y = 議事錄_count), stat = "identity", fill = "red", alpha = 0.5) + -labs( -title = "Meeting Records Completeness by Term", -x = "Term", -y = "Count" -) + -theme_minimal() -# Create meeting records completeness analysis plot -ggplot(meeting_stats, aes(x = term)) + -geom_bar(aes(y = count), stat = "identity", fill = "blue", alpha = 0.5) + -geom_bar(aes(y = `議事錄_count`), stat = "identity", fill = "red", alpha = 0.5) + -labs( -title = "Meeting Records Completeness by Term", -x = "Term", -y = "Count" -) + -theme_minimal() -# Create meeting records completeness analysis plot -x <- ggplot(meeting_stats, aes(x = term)) + -geom_bar(aes(y = count), stat = "identity", fill = "blue", alpha = 0.5) + -geom_bar(aes(y = `議事錄_count`), stat = "identity", fill = "red", alpha = 0.5) + -labs( -title = "Meeting Records Completeness by Term", -x = "Term", -y = "Count" -) + -theme_minimal() -x -# Create meeting records completeness analysis plot -ggplot(meeting_stats, aes(x = term)) + -geom_bar(aes(y = count), stat = "identity", fill = "blue", alpha = 0.5) + -geom_bar(aes(y = `議事錄_count`), stat = "identity", fill = "red", alpha = 0.5) + -labs( -title = "Meeting Records Completeness by Term", -x = "Term", -y = "Count" -) + -theme_minimal() -stats <- get_tly_stat() -stats -stats$bill$terms -roxygen2::roxygenise() -roxygen2::roxygenise() -roxygen2::roxygenise() +devtools::load_all(".") +get_ly_committees_type() +x <- get_ly_committees_type() roxygen2::roxygenise() roxygen2::roxygenise() -roxygen2::roxygenise() -roxygen2::roxygenise() -stats <- get_tly_stat() -analyze_bills(stats) -analyze_bills -analyze_bills(stats) -analyze_meetings(stats) -analyze_ivod(stats) -create_interactive_plot(stats) -library(pkgdown) -build_site() -build_site() -build_site() build_site() +deploy_to_branch() build_site() deploy_to_branch() +------ +review_session_info() +library(legisTaiwan) +review_session_info() +review_session_info +?review_session_info +review_session_info(7) +get_variable_info() +review_session_info(7) +review_session_info <- function(term) { +# Input validation +if(missing(term)) { +stop("Term parameter is required") +} +attempt::stop_if_not(website_availability2(), +msg = "API connection error. Please check your internet connection.") +attempt::stop_if(term, is.null, +msg = "Term cannot be NULL. Please provide a valid term number (1-11).") +attempt::stop_if_not(term %in% 1:11, +msg = paste("Invalid term:", term, +"\nPlease provide a term number between 1 and 11.")) +# Construct URL +url <- sprintf("https://npl.ly.gov.tw/do/www/appDate?status=0&expire=%02d&startYear=0", +as.numeric(term)) +tryCatch({ +# Parse HTML +html_ <- rvest::html_nodes(rvest::read_html(url), +"*[class='section_wrapper']") +# Extract titles +title <- stringr::str_split_1( +rvest::html_text2( +rvest::html_nodes(html_, "[class='tt_titlebar2']") +), +"\t\r" +)[1:2] +# Extract rows +odd_rows <- rvest::html_text2( +rvest::html_nodes(html_, "[class='tt_listrow_odd']") +) +even_rows <- rvest::html_text2( +rvest::html_nodes(html_, "[class='tt_listrow_even']") +) +# Process data +data <- lapply( +lapply(c(odd_rows, even_rows), +function(x) stringr::str_split_1(x, "\r\r")), +function(x) gsub("[[:space:]]", "", x) +) +# Create dataframe +df <- do.call(rbind, data) +colnames(df) <- title +return(tibble::as_tibble(df)) +}, +error = function(e) { +stop(paste("Error retrieving session information:", e$message)) +}) +} +review_session_info() +review_session_info(7) +library(roxygence) roxygen2::roxygenise() +review_session_info(7) +review_session_info(7) roxygen2::roxygenise() +review_session_info(7) +review_session_info(7) roxygen2::roxygenise() roxygen2::roxygenise() roxygen2::roxygenise() -library(legisTaiwan) -devtools::check(args = c('--no-codoc', '--no-manual', '--no-check-ASCII')) -library(stringi) -# 读取文件内容 -file_content <- readLines("R/bill.R", encoding = "UTF-8") -file_content -writeLines(file_content, "R/bill.R", useBytes = TRUE) roxygen2::roxygenise() +legislators_data <- get_legislators(term = 9) +legislators_data roxygen2::roxygenise() +check_bill <- get_variable_info("get_bills") +check_bill +check_bill <- get_variable_info("get_caucus_meetings") +check_bill +check_caucus <- get_variable_info("get_caucus_meetings") +check_caucus roxygen2::roxygenise() roxygen2::roxygenise() roxygen2::roxygenise() roxygen2::roxygenise() roxygen2::roxygenise() roxygen2::roxygenise() +get_variable_info("get_speech_video") +get_speech_video("10") +get_speech_video(term = 11) +get_speech_video(term = 11, start_date = 110/10/1, end_date = 110/12/1) roxygen2::roxygenise() roxygen2::roxygenise() -build_site() roxygen2::roxygenise() -build_site() -deploy_to_branch() -library(pkgdown) -build_site() +roxygen2::roxygenise() +library(pkgdown ) build_site() build_site() -roxygen2::roxygenize() -roxygen2::roxygenize() build_site() roxygen2::roxygenise() -pkgload::dev_help('.onAttach') -pkgload::dev_help('calculate_bill_trends') -pkgload::dev_help('calculate_bill_trends') roxygen2::roxygenise() roxygen2::roxygenise() roxygen2::roxygenise() -roxygen2::roxygenise() -build_site() build_site() +roxygen2::roxygenise() +roxygen2::roxygenise() build_site() deploy_to_branch() diff --git a/.Rproj.user/763C8F27/pcs/source-pane.pper b/.Rproj.user/763C8F27/pcs/source-pane.pper index bc7dc995..ddca97d7 100644 --- a/.Rproj.user/763C8F27/pcs/source-pane.pper +++ b/.Rproj.user/763C8F27/pcs/source-pane.pper @@ -1,3 +1,3 @@ { - "activeTab": 4 + "activeTab": 2 } \ No newline at end of file diff --git a/.Rproj.user/763C8F27/pcs/windowlayoutstate.pper b/.Rproj.user/763C8F27/pcs/windowlayoutstate.pper index cd8bb8e3..44a90a40 100644 --- a/.Rproj.user/763C8F27/pcs/windowlayoutstate.pper +++ b/.Rproj.user/763C8F27/pcs/windowlayoutstate.pper @@ -1,14 +1,14 @@ { "left": { - "splitterpos": 338, + "splitterpos": 372, "topwindowstate": "NORMAL", - "panelheight": 931, - "windowheight": 945 + "panelheight": 1026, + "windowheight": 1040 }, "right": { - "splitterpos": 467, + "splitterpos": 514, "topwindowstate": "NORMAL", - "panelheight": 931, - "windowheight": 945 + "panelheight": 1026, + "windowheight": 1040 } } \ No newline at end of file diff --git a/.Rproj.user/763C8F27/pcs/workbench-pane.pper b/.Rproj.user/763C8F27/pcs/workbench-pane.pper index c690b613..597ecbce 100644 --- a/.Rproj.user/763C8F27/pcs/workbench-pane.pper +++ b/.Rproj.user/763C8F27/pcs/workbench-pane.pper @@ -1,5 +1,5 @@ { - "TabSet1": 2, + "TabSet1": 5, "TabSet2": 1, "TabZoom": {} } \ No newline at end of file diff --git a/.Rproj.user/763C8F27/persistent-state b/.Rproj.user/763C8F27/persistent-state index c1b10be3..604304a7 100644 --- a/.Rproj.user/763C8F27/persistent-state +++ b/.Rproj.user/763C8F27/persistent-state @@ -1,6 +1,6 @@ build-last-errors="[]" build-last-errors-base-dir="~/Dropbox/My Packages/legisTaiwan/" -build-last-outputs="[{\"type\":0,\"output\":\"==> R CMD INSTALL --preclean --no-multiarch --with-keep.source legisTaiwan\\n\\n\"},{\"type\":1,\"output\":\"* installing to library ‘/Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library’\\n\"},{\"type\":1,\"output\":\"* installing *source* package ‘legisTaiwan’ ...\\n\"},{\"type\":1,\"output\":\"\"},{\"type\":1,\"output\":\"** using staged installation\\n\"},{\"type\":1,\"output\":\"** R\\n\"},{\"type\":1,\"output\":\"\"},{\"type\":1,\"output\":\"** data\\n\"},{\"type\":1,\"output\":\"*** moving datasets to lazyload DB\\n\"},{\"type\":1,\"output\":\"** inst\\n\"},{\"type\":1,\"output\":\"** byte-compile and prepare package for lazy loading\\n\"},{\"type\":1,\"output\":\"\"},{\"type\":1,\"output\":\"** help\\n\"},{\"type\":1,\"output\":\"\"},{\"type\":1,\"output\":\"*** installing help indices\\n\"},{\"type\":1,\"output\":\"\"},{\"type\":1,\"output\":\"*** copying figures\\n\"},{\"type\":1,\"output\":\"** building package indices\\n\"},{\"type\":1,\"output\":\"\"},{\"type\":1,\"output\":\"** installing vignettes\\n\"},{\"type\":1,\"output\":\"** testing if installed package can be loaded from temporary location\\n\"},{\"type\":1,\"output\":\"\"},{\"type\":1,\"output\":\"** testing if installed package can be loaded from final location\\n\"},{\"type\":1,\"output\":\"\"},{\"type\":1,\"output\":\"** testing if installed package keeps a record of temporary installation path\\n\"},{\"type\":1,\"output\":\"* DONE (legisTaiwan)\\n\"},{\"type\":1,\"output\":\"\"}]" +build-last-outputs="[{\"type\":0,\"output\":\"==> R CMD INSTALL --preclean --no-multiarch --with-keep.source legisTaiwan\\n\\n\"},{\"type\":1,\"output\":\"* installing to library ‘/Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library/_build’\\n\"},{\"type\":1,\"output\":\"* installing *source* package ‘legisTaiwan’ ...\\n\"},{\"type\":1,\"output\":\"** using staged installation\\n\"},{\"type\":1,\"output\":\"\"},{\"type\":1,\"output\":\"** R\\n\"},{\"type\":1,\"output\":\"** data\\n\"},{\"type\":1,\"output\":\"*** moving datasets to lazyload DB\\n\"},{\"type\":1,\"output\":\"\"},{\"type\":1,\"output\":\"** inst\\n\"},{\"type\":1,\"output\":\"\"},{\"type\":1,\"output\":\"** byte-compile and prepare package for lazy loading\\n\"},{\"type\":1,\"output\":\"\"},{\"type\":1,\"output\":\"** help\\n\"},{\"type\":1,\"output\":\"\"},{\"type\":1,\"output\":\"*** installing help indices\\n\"},{\"type\":1,\"output\":\"\"},{\"type\":1,\"output\":\"*** copying figures\\n\"},{\"type\":1,\"output\":\"** building package indices\\n\"},{\"type\":1,\"output\":\"\"},{\"type\":1,\"output\":\"** installing vignettes\\n\"},{\"type\":1,\"output\":\"** testing if installed package can be loaded from temporary location\\n\"},{\"type\":1,\"output\":\"\"},{\"type\":1,\"output\":\"** testing if installed package can be loaded from final location\\n\"},{\"type\":1,\"output\":\"\"},{\"type\":1,\"output\":\"** testing if installed package keeps a record of temporary installation path\\n\"},{\"type\":1,\"output\":\"* DONE (legisTaiwan)\\n\"},{\"type\":1,\"output\":\"\"}]" compile_pdf_state="{\"tab_visible\":false,\"running\":false,\"target_file\":\"\",\"output\":\"\",\"errors\":[]}" files.monitored-path="" find-in-files-state="{\"handle\":\"\",\"input\":\"\",\"path\":\"\",\"regex\":false,\"ignoreCase\":false,\"results\":{\"file\":[],\"line\":[],\"lineValue\":[],\"matchOn\":[],\"matchOff\":[],\"replaceMatchOn\":[],\"replaceMatchOff\":[]},\"running\":false,\"replace\":false,\"preview\":false,\"gitFlag\":false,\"replacePattern\":\"\"}" diff --git a/.Rproj.user/763C8F27/rmd-outputs b/.Rproj.user/763C8F27/rmd-outputs index e740db6d..a142ada8 100644 --- a/.Rproj.user/763C8F27/rmd-outputs +++ b/.Rproj.user/763C8F27/rmd-outputs @@ -1,5 +1,5 @@ /private/var/folders/60/xlhp81vn4_79cp2dbjgy07tm0000gn/T/RtmpnIcpqT/preview-b0a385c2b7c.html -/private/var/folders/60/xlhp81vn4_79cp2dbjgy07tm0000gn/T/Rtmpfs6ED9/preview-47ce20db576c.html +/private/var/folders/60/xlhp81vn4_79cp2dbjgy07tm0000gn/T/Rtmpmb2Owd/preview-82161d0c7f9a.html /private/var/folders/60/xlhp81vn4_79cp2dbjgy07tm0000gn/T/RtmpnIcpqT/preview-184ca2a28b82f.dir/quickstart.html /private/var/folders/60/xlhp81vn4_79cp2dbjgy07tm0000gn/T/RtmpnIcpqT/preview-184ca1b7bd20.dir/quickstart.html /private/var/folders/60/xlhp81vn4_79cp2dbjgy07tm0000gn/T/RtmpnIcpqT/preview-3a97368633ab.html diff --git a/.Rproj.user/763C8F27/sources/per/t/115577B3 b/.Rproj.user/763C8F27/sources/per/t/115577B3 deleted file mode 100644 index 44806904..00000000 --- a/.Rproj.user/763C8F27/sources/per/t/115577B3 +++ /dev/null @@ -1,27 +0,0 @@ -{ - "id": "115577B3", - "path": "~/Dropbox/My Packages/legisTaiwan/R/get_ly_legislators_by_term.R", - "project_path": "R/get_ly_legislators_by_term.R", - "type": "r_source", - "hash": "220351508", - "contents": "", - "dirty": false, - "created": 1736027729958.0, - "source_on_save": false, - "relative_order": 7, - "properties": { - "tempName": "Untitled1", - "source_window_id": "", - "Source": "Source", - "cursorPosition": "78,0", - "scrollLine": "58" - }, - "folds": "", - "lastKnownWriteTime": 1736027739, - "encoding": "UTF-8", - "collab_server": "", - "source_window": "", - "last_content_update": 1736027739296, - "read_only": false, - "read_only_alternatives": [] -} \ No newline at end of file diff --git a/.Rproj.user/763C8F27/sources/per/t/115577B3-contents b/.Rproj.user/763C8F27/sources/per/t/115577B3-contents deleted file mode 100644 index 462a1b6c..00000000 --- a/.Rproj.user/763C8F27/sources/per/t/115577B3-contents +++ /dev/null @@ -1,200 +0,0 @@ -#' Get Legislative Yuan Legislators by Term -#' -#' @title Fetch Legislators List for a Specific Term -#' -#' @description -#' Retrieves a paginated list of legislators for a specific Legislative Yuan term. -#' The function provides detailed information about legislators including their names, -#' parties, and represented areas. It also includes metadata about the total number -#' of legislators and pagination information. -#' -#' @param term required integer. Legislative term number (e.g., 9) -#' @param page integer. Page number for pagination (default: 1) -#' @param limit integer. Number of records per page (default: 20) -#' @param show_progress logical. Whether to display progress bar and summary statistics (default: TRUE) -#' -#' @return A list with two components: -#' \describe{ -#' \item{metadata}{A list containing: -#' \describe{ -#' \item{total}{Total number of legislators} -#' \item{total_page}{Total number of pages} -#' \item{current_page}{Current page number} -#' \item{per_page}{Number of records per page} -#' } -#' } -#' \item{legislators}{A data frame containing legislator information: -#' \describe{ -#' \item{term}{Legislative term} -#' \item{name}{Legislator's name} -#' \item{party}{Political party affiliation} -#' \item{areaName}{Represented area (if available)} -#' \item{columns}{Additional columns as provided by the API} -#' } -#' } -#' } -#' -#' @details -#' The function includes a progress bar and detailed summary statistics when -#' show_progress is TRUE. The summary includes: -#' \describe{ -#' \item{Total Statistics}{Total number of legislators} -#' \item{Pagination}{Current page and total pages} -#' \item{Page Size}{Records per page} -#' \item{Distribution}{Party and area distribution (if available)} -#' } -#' -#' @examples -#' \dontrun{ -#' # Get first page of legislators for term 9 -#' result <- get_ly_legislators_by_term(term = 9) -#' -#' # Get second page with 30 records per page -#' result <- get_ly_legislators_by_term( -#' term = 9, -#' page = 2, -#' limit = 30 -#' ) -#' -#' # Access the results -#' metadata <- result$metadata -#' legislators_df <- result$legislators -#' -#' # Display total number of legislators -#' cat("Total legislators:", metadata$total, "\n") -#' -#' # Show first few rows of legislator data -#' head(legislators_df) -#' } -#' -#' @seealso -#' \describe{ -#' \item{get_ly_legislator_detail}{\code{\link{get_ly_legislator_detail}} for getting detailed information about a specific legislator} -#' } -#' -#' @importFrom httr GET content status_code -#' @importFrom jsonlite fromJSON -#' @importFrom utils setTxtProgressBar txtProgressBar -#' @encoding UTF-8 -#' @export -get_ly_legislators_by_term <- function( - term, - page = 1, - limit = 20, - show_progress = TRUE -) { - # Parameter validation - if (missing(term)) { - stop("term parameter is required") - } - if (!is.numeric(term)) { - stop("term must be numeric") - } - # Initialize progress - if(show_progress) { - cat(sprintf("\nFetching legislators data for term %d...\n", term)) - pb <- txtProgressBar(min = 0, max = 100, style = 3) - setTxtProgressBar(pb, 20) - } - - # Base URL - base_url <- sprintf("https://ly.govapi.tw/legislator/%d", term) - - # Query parameters - query_params <- list( - page = page, - limit = limit - ) - - # Update progress - API call - if(show_progress) { - setTxtProgressBar(pb, 40) - } - - # Send GET request - response <- httr::GET( - base_url, - query = query_params - ) - - # Check response status - if (httr::status_code(response) != 200) { - if(show_progress) close(pb) - stop("API request failed with status code: ", httr::status_code(response)) - } - - # Update progress - parsing - if(show_progress) { - setTxtProgressBar(pb, 60) - } - - # Parse response - content <- httr::content(response, "text", encoding = "UTF-8") - data <- jsonlite::fromJSON(content, simplifyDataFrame = TRUE, flatten = TRUE) - - # Extract metadata - metadata <- list( - total = data$total$value, - total_page = data$total_page, - current_page = data$page, - per_page = data$limit - ) - - # Update progress - data processing - if(show_progress) { - setTxtProgressBar(pb, 80) - } - - # Process legislators data - if (length(data$legislators) > 0) { - legislators_df <- data.frame( - data$legislators, - stringsAsFactors = FALSE - ) - } else { - legislators_df <- data.frame( - term = integer(), - name = character(), - party = character(), - stringsAsFactors = FALSE - ) - } - - # Update progress - complete - if(show_progress) { - setTxtProgressBar(pb, 100) - close(pb) - - # Print summary - cat("\n\n") - cat("====== Retrieved Information ======\n") - cat("-----------------------------------\n") - cat(sprintf("Total Legislators: %d\n", metadata$total)) - cat(sprintf("Page: %d of %d\n", metadata$current_page, metadata$total_page)) - cat(sprintf("Records per page: %d\n", metadata$per_page)) - - if(nrow(legislators_df) > 0) { - # Add party distribution - party_counts <- table(legislators_df$party) - cat("\nParty Distribution:\n") - for(party in names(party_counts)) { - cat(sprintf(" %s: %d\n", party, party_counts[party])) - } - - # Add area distribution if available - if("areaName" %in% names(legislators_df)) { - area_counts <- table(legislators_df$areaName) - cat("\nArea Distribution:\n") - for(area in names(area_counts)) { - cat(sprintf(" %s: %d\n", area, area_counts[area])) - } - } - } - cat("===================================\n") - } - - return(list( - metadata = metadata, - legislators = legislators_df - )) -} diff --git a/.Rproj.user/763C8F27/sources/per/t/2949E748 b/.Rproj.user/763C8F27/sources/per/t/2949E748 deleted file mode 100644 index 11814399..00000000 --- a/.Rproj.user/763C8F27/sources/per/t/2949E748 +++ /dev/null @@ -1,28 +0,0 @@ -{ - "id": "2949E748", - "path": "~/Dropbox/My Packages/legisTaiwan/vignettes/quickstart.Rmd", - "project_path": "vignettes/quickstart.Rmd", - "type": "r_markdown", - "hash": "1385681139", - "contents": "", - "dirty": false, - "created": 1736023633832.0, - "source_on_save": false, - "relative_order": 17, - "properties": { - "source_window_id": "", - "Source": "Source", - "cursorPosition": "90,5", - "scrollLine": "69", - "docOutlineVisible": "1", - "docOutlineSize": "286" - }, - "folds": "", - "lastKnownWriteTime": 1736024422, - "encoding": "UTF-8", - "collab_server": "", - "source_window": "", - "last_content_update": 1736024422643, - "read_only": false, - "read_only_alternatives": [] -} \ No newline at end of file diff --git a/.Rproj.user/763C8F27/sources/per/t/2949E748-contents b/.Rproj.user/763C8F27/sources/per/t/2949E748-contents deleted file mode 100644 index b0e5b578..00000000 --- a/.Rproj.user/763C8F27/sources/per/t/2949E748-contents +++ /dev/null @@ -1,133 +0,0 @@ ---- -title: "Quick Start" -output: rmarkdown::html_vignette -vignette: > - %\VignetteIndexEntry{Quick Start} - %\VignetteEngine{knitr::rmarkdown} - %\VignetteEncoding{UTF-8} ---- - -```{r, include = FALSE} -knitr::opts_chunk$set( - collapse = TRUE, - comment = "#>" -) -``` - -## Get Started with Using [`remotes`](https://github.com/r-lib/remotes): - -
- -**`legisTaiwan`** is an R package for accessing [Taiwan Legislative Yuan API](https://data.ly.gov.tw/index.action). The goal of `legisTaiwan` is to make it quickly and instantly download Taiwan's legislative data, digitized textual -and video records for a research project and analyze public policies. - -
- - -```{r eval = FALSE} -install.packages("remotes") -remotes::install_github("davidycliao/legisTaiwan", force = TRUE) -``` - -```{r} -library(legisTaiwan) -``` - - -```{r include=FALSE} -assign("has_internet_via_proxy", TRUE, environment(curl::has_internet)) -``` - - - -## Taiwan Legislative Yuan API (v2) - -
- -The Legislative Yuan API is transitioning from `https://ly.govapi.tw` to `https://v2.ly.govapi.tw`. - -While we are maintaining support for functions that use the legacy API, please note that the old API endpoint will eventually be deprecated. We recommend users to gradually transition to the newer API versions as they become available. - -**Current Status:** - -- Legacy API (`ly.govapi.tw`) - Still functional but will not receive updates -- New API (`v2.ly.govapi.tw`) - Current active development and maintenance - - -
- -
- -### Statistical Information - -- [`get_tly_stat()`](): Fetch and Parse Legislative Yuan Statistics - - -### Legislators - -- [`get_ly_legislator_detail()`](): Retrieve Complete Historical Records of Legislators -- [`get_ly_legislators_by_term()`](): Get Legislators by Legislative Term -- [`get_ly_legislator_cosign_bills()`](): Retrieve Legislator's Co-sponsored Bills -- [`get_ly_legislator_bills()`](): Get Bills Proposed by Legislator - -### Bill - -- [`get_ly_bills()`](): Fetch and Parse Legislative Yuan Bills - -### Committees - -- [`get_ly_committee_meets()`](): Fetch Legislative Yuan Committee Meetings - -- [`get_ly_committees_type()`](): Fetch and Parse Legislative Yuan Committee Details, Jurisdiction and Codes - -### Interpellation - -- [`get_ly_interpellations()`](): Get Legislative Yuan Interpellation Records - -### IVOD - -- [`get_ly_ivod()`](): Get Legislative Yuan IVOD Records - -
- -## Taiwan Legislative Yuan API (v1) - -We will provide comprehensive guides and documentation to help you migrate to the new API endpoints. - -- [`get_parlquestions()`](https://davidycliao.github.io/legisTaiwan/reference/get_parlquestions.html): parliamentary questions asked by the legislators 提供議事日程本院委員之質詢事項資訊 (自第8屆) - -- [`get_meetings()`](https://davidycliao.github.io/legisTaiwan/reference/get_bills.html): spoken meeting records 委員發言 - -- [`get_caucus_meetings()`](https://davidycliao.github.io/legisTaiwan/reference/get_caucus_meetings.html): the meeting records of cross-caucus session 提供公報之黨團協商資訊 (自第8屆) - -- [`get_executive_response()`](https://davidycliao.github.io/legisTaiwan/reference/get_executive_response.html): questions answered by the executives提供公報質詢事項行政院答復資訊 (自第8屆) - -- [`get_public_debates()`](https://davidycliao.github.io/legisTaiwan/reference/get_public_debates.html): public debates 提供公報之國是論壇資訊,並包含書面意見自 (自第8屆) - -- [`get_speech_video()`](https://davidycliao.github.io/legisTaiwan/reference/get_speech_video.html): full video information of meetings and committees 提供立法院院會及委員會之委員發言片段相關影片資訊 (自第9屆) - -- [`get_committee_record()`](https://davidycliao.github.io/legisTaiwan/reference/get_committee_record.html): the records of reviewed items in the committees 提供委員會會議審查之議案項目 (自第8屆) - -- [`get_bills()`](https://davidycliao.github.io/legisTaiwan/reference/get_bills.html): the records of the bills 法律提案 (能取得最早日不詳,待檢查) - -- [`get_bills_2()`](https://davidycliao.github.io/legisTaiwan/reference/get_bills_2.html): the records of legislators and the government bill proposals 提供委員及政府之議案提案資訊 (自第8屆) - -- [`passed_legislation()`](https://data.ly.gov.tw/getds.action?id=48): legislation and information passed on the third reading 提供公報院會紀錄之三讀通過議案資訊。(自第8屆第1會期起) **coming soon** - -- [`get_variable_info()`](https://davidycliao.github.io/legisTaiwan/reference/get_variable_info.html): the API’s endpoint user manuals 使用說明文件 - -- [`review_session_info()`](https://davidycliao.github.io/legisTaiwan/reference/review_session_info.html): the session period and year in formatted in Minguo (ROC) calendar. 屆期年對照表 - - -- [`get_legislators()`](https://davidycliao.github.io/legisTaiwan/reference/get_legislators.html): legislator demographics 提供委員基本資料 - -
- -## How to Contribute - -
-Contributions in the form of comments, code suggestions, and tutorial examples are very welcome. Please note that the `LeigsTaiwan` is released with the [Contributor Code of Conduct](https://github.com/davidycliao/legisTaiwan/blob/master/CONDUCT.md). By contributing to this project, you agree to abide by its terms. - -
- -
diff --git a/.Rproj.user/763C8F27/sources/per/t/4152F724 b/.Rproj.user/763C8F27/sources/per/t/4152F724 deleted file mode 100644 index 7120ac75..00000000 --- a/.Rproj.user/763C8F27/sources/per/t/4152F724 +++ /dev/null @@ -1,26 +0,0 @@ -{ - "id": "4152F724", - "path": "~/Dropbox/My Packages/legisTaiwan/R/get_ly_interpellations.R", - "project_path": "R/get_ly_interpellations.R", - "type": "r_source", - "hash": "318249443", - "contents": "", - "dirty": false, - "created": 1736027643314.0, - "source_on_save": false, - "relative_order": 5, - "properties": { - "source_window_id": "", - "Source": "Source", - "cursorPosition": "0,0", - "scrollLine": "0" - }, - "folds": "", - "lastKnownWriteTime": 1736027648, - "encoding": "UTF-8", - "collab_server": "", - "source_window": "", - "last_content_update": 1736027648739, - "read_only": false, - "read_only_alternatives": [] -} \ No newline at end of file diff --git a/.Rproj.user/763C8F27/sources/per/t/4152F724-contents b/.Rproj.user/763C8F27/sources/per/t/4152F724-contents deleted file mode 100644 index 7978d3ec..00000000 --- a/.Rproj.user/763C8F27/sources/per/t/4152F724-contents +++ /dev/null @@ -1,204 +0,0 @@ -#' @title Get Legislative Yuan Interpellation Records -#' -#' @description -#' Fetches and parses interpellation records from the Legislative Yuan API. -#' Supports filtering by legislator, term, session and keyword search. -#' Returns structured data including metadata and detailed interpellation records. -#' -#' @param page An integer specifying the page number (default: 1) -#' @param limit An integer specifying the number of records per page (default: 20) -#' @param legislator A string specifying the legislator's name -#' @param term An integer specifying the legislative term number -#' @param session_period An integer specifying the session period -#' @param session_times An integer specifying the session times -#' @param meet_id A string specifying the meeting ID (e.g., "院會-9-2-1") -#' @param query A string to search in interpellation reasons or content -#' @param show_progress A logical value indicating whether to show progress bar (default: TRUE) -#' -#' @return A list with two components: -#' \describe{ -#' \item{metadata}{A list containing pagination and filter information: -#' \describe{ -#' \item{total}{Total number of records found} -#' \item{total_page}{Total number of pages} -#' \item{current_page}{Current page number} -#' \item{per_page}{Number of records per page} -#' \item{filters_used}{List of filters applied} -#' } -#' } -#' \item{interpellations}{A data frame containing interpellation records: -#' \describe{ -#' \item{id}{Interpellation ID} -#' \item{printed_at}{Date when printed} -#' \item{reason}{Interpellation reason} -#' \item{description}{Detailed content} -#' \item{legislators}{Comma-separated list of legislators} -#' \item{meet_id}{Meeting ID} -#' \item{term}{Legislative term} -#' \item{sessionPeriod}{Session period} -#' \item{sessionTimes}{Session times} -#' \item{ppg_url}{URL to the parliamentary record} -#' } -#' } -#' } -#' -#' @examples -#' \dontrun{ -#' # Get interpellations by legislator -#' zhao_records <- get_ly_interpellations( -#' legislator = "趙天麟", -#' limit = 5 -#' ) -#' -#' # Get interpellations for specific term and session -#' session_records <- get_ly_interpellations( -#' term = 9, -#' session_period = 2, -#' session_times = 1 -#' ) -#' -#' # Search interpellations by keyword -#' search_results <- get_ly_interpellations( -#' query = "氫能", -#' page = 1, -#' limit = 20 -#' ) -#' -#' # View results -#' print(paste("Total records:", search_results$metadata$total)) -#' head(search_results$interpellations) -#' } -#' -#' @importFrom httr GET content status_code -#' @importFrom jsonlite fromJSON -#' @importFrom utils txtProgressBar setTxtProgressBar -#' -#' @seealso -#' \url{https://ly.govapi.tw/} for API documentation -#' -#' @encoding UTF-8 -#' @export -get_ly_interpellations <- function( - page = 1, - limit = 20, - legislator = NULL, - term = NULL, - session_period = NULL, - session_times = NULL, - meet_id = NULL, - query = NULL, - show_progress = TRUE -) { - # Base URL - base_url <- "https://ly.govapi.tw/interpellation" - - # Query parameters - query_params <- list( - page = page, - limit = limit, - term = term, - sessionPeriod = session_period, - sessionTimes = session_times, - legislator = legislator, - meet_id = meet_id, - q = query - ) - - # Remove NULL values - query_params <- query_params[!sapply(query_params, is.null)] - - if (show_progress) { - cat("Fetching interpellation data...\n") - } - - # Send GET request - response <- httr::GET( - base_url, - query = query_params - ) - - # Check response status - if (httr::status_code(response) != 200) { - stop("API request failed with status code: ", httr::status_code(response)) - } - - # Parse response - content <- httr::content(response, "text", encoding = "UTF-8") - data <- jsonlite::fromJSON(content, simplifyDataFrame = TRUE, flatten = TRUE) - - # Extract metadata - metadata <- list( - total = data$total$value, - total_page = data$total_page, - current_page = data$page, - per_page = data$limit, - filters_used = query_params - ) - - # Process interpellations - if (length(data$interpellations) > 0) { - if (show_progress) { - cat("Processing", nrow(data$interpellations), "records...\n") - pb <- txtProgressBar(min = 0, max = nrow(data$interpellations), style = 3) - } - - # Create dataframe with progress bar - fields <- c("id", "printed_at", "reason", "description", "meet_id", - "term", "sessionPeriod", "sessionTimes", "ppg_url", - "page_start", "page_end") - - interpellations_list <- vector("list", nrow(data$interpellations)) - - for(i in 1:nrow(data$interpellations)) { - if (show_progress) { - setTxtProgressBar(pb, i) - } - - # Extract record - record <- data$interpellations[i,] - - # Create row data - row_data <- c( - sapply(fields, function(f) ifelse(is.null(record[[f]]), NA, record[[f]])), - legislators = paste(unlist(record$legislators), collapse = ", ") - ) - - interpellations_list[[i]] <- row_data - } - - if (show_progress) { - close(pb) - cat("\nProcessing complete!\n") - } - - # Convert list to dataframe - interpellations_df <- do.call(rbind.data.frame, - lapply(interpellations_list, - function(x) as.data.frame(t(x), - stringsAsFactors = FALSE))) - names(interpellations_df) <- c(fields, "legislators") - - } else { - # Empty dataframe with correct structure - interpellations_df <- data.frame( - id = character(), - printed_at = character(), - reason = character(), - description = character(), - legislators = character(), - meet_id = character(), - term = integer(), - sessionPeriod = integer(), - sessionTimes = integer(), - ppg_url = character(), - page_start = integer(), - page_end = integer(), - stringsAsFactors = FALSE - ) - } - - return(list( - metadata = metadata, - interpellations = interpellations_df - )) -} diff --git a/.Rproj.user/763C8F27/sources/per/t/461AEA8B b/.Rproj.user/763C8F27/sources/per/t/461AEA8B deleted file mode 100644 index 3faa3b60..00000000 --- a/.Rproj.user/763C8F27/sources/per/t/461AEA8B +++ /dev/null @@ -1,27 +0,0 @@ -{ - "id": "461AEA8B", - "path": "~/Dropbox/My Packages/legisTaiwan/R/get_ly_legislator_detail.R", - "project_path": "R/get_ly_legislator_detail.R", - "type": "r_source", - "hash": "1158290550", - "contents": "", - "dirty": false, - "created": 1736027696776.0, - "source_on_save": false, - "relative_order": 6, - "properties": { - "tempName": "Untitled1", - "source_window_id": "", - "Source": "Source", - "cursorPosition": "0,0", - "scrollLine": "0" - }, - "folds": "", - "lastKnownWriteTime": 1736027703, - "encoding": "UTF-8", - "collab_server": "", - "source_window": "", - "last_content_update": 1736027703885, - "read_only": false, - "read_only_alternatives": [] -} \ No newline at end of file diff --git a/.Rproj.user/763C8F27/sources/per/t/461AEA8B-contents b/.Rproj.user/763C8F27/sources/per/t/461AEA8B-contents deleted file mode 100644 index c946e6d1..00000000 --- a/.Rproj.user/763C8F27/sources/per/t/461AEA8B-contents +++ /dev/null @@ -1,89 +0,0 @@ -#' Get Legislative Yuan Legislator Detail -#' -#' @title Fetch Legislator Detail Information -#' -#' @description -#' Retrieves detailed information for a specific legislator by term and name from the Legislative Yuan API. -#' -#' @param term required integer. Legislative term number (e.g. 9) -#' @param name required string. Legislator name (e.g. "王金平") -#' @param show_progress logical. Whether to display progress info (default: TRUE) -#' -#' @return A list containing legislator details: -#' \describe{ -#' \item{term}{Legislative term number} -#' \item{name}{Legislator's name in Chinese} -#' \item{ename}{Legislator's name in English} -#' \item{sex}{Gender} -#' \item{party}{Political party affiliation} -#' \item{partyGroup}{Legislative party group} -#' \item{areaName}{Represented area} -#' \item{committee}{Committee assignments by session} -#' \item{onboardDate}{Date took office} -#' \item{degree}{Education background} -#' \item{experience}{Work experience} -#' \item{picUrl}{URL of legislator's photo} -#' \item{leaveFlag}{Whether has left office} -#' \item{leaveDate}{Date left office if applicable} -#' \item{leaveReason}{Reason for leaving if applicable} -#' \item{bioId}{Biography ID} -#' } -#' -#' @examples -#' \dontrun{ -#' # Get legislator detail -#' detail <- get_ly_legislator_detail( -#' term = 9, -#' name = "王金平" -#' ) -#' -#' # Print basic info -#' cat(sprintf( -#' "Name: %s (%s)\nParty: %s\nArea: %s\n", -#' detail$name, -#' detail$ename, -#' detail$party, -#' detail$areaName -#' )) -#' } -#' -#' @importFrom httr GET content status_code -#' @importFrom jsonlite fromJSON -#' @encoding UTF-8 -#' @export -get_ly_legislator_detail <- function( - term, - name, - show_progress = TRUE -) { - # Parameter validation - if (missing(term)) stop("term parameter is required") - if (missing(name)) stop("name parameter is required") - if (!is.numeric(term)) stop("term must be numeric") - if (!is.character(name)) stop("name must be character") - - # Base URL with path parameters - base_url <- sprintf("https://ly.govapi.tw/legislator/%d/%s", term, name) - - if (show_progress) { - cat(sprintf("Fetching details for legislator %s (term %d)...\n", name, term)) - } - - # Send GET request - response <- httr::GET(base_url) - - # Check response status - if (httr::status_code(response) != 200) { - stop("API request failed with status code: ", httr::status_code(response)) - } - - # Parse response - content <- httr::content(response, "text", encoding = "UTF-8") - data <- jsonlite::fromJSON(content) - - if (show_progress) { - cat("Data retrieved successfully!\n") - } - - return(data) -} diff --git a/.Rproj.user/763C8F27/sources/per/t/53011D1D b/.Rproj.user/763C8F27/sources/per/t/53011D1D deleted file mode 100644 index f10b9a93..00000000 --- a/.Rproj.user/763C8F27/sources/per/t/53011D1D +++ /dev/null @@ -1,26 +0,0 @@ -{ - "id": "53011D1D", - "path": "~/Dropbox/My Packages/legisTaiwan/DESCRIPTION", - "project_path": "DESCRIPTION", - "type": "dcf", - "hash": "2131181659", - "contents": "", - "dirty": false, - "created": 1736027028305.0, - "source_on_save": false, - "relative_order": 6, - "properties": { - "source_window_id": "", - "Source": "Source", - "cursorPosition": "32,10", - "scrollLine": "14" - }, - "folds": "", - "lastKnownWriteTime": 1736027037, - "encoding": "UTF-8", - "collab_server": "", - "source_window": "", - "last_content_update": 1736027037608, - "read_only": false, - "read_only_alternatives": [] -} \ No newline at end of file diff --git a/.Rproj.user/763C8F27/sources/per/t/53011D1D-contents b/.Rproj.user/763C8F27/sources/per/t/53011D1D-contents deleted file mode 100644 index de36c6e1..00000000 --- a/.Rproj.user/763C8F27/sources/per/t/53011D1D-contents +++ /dev/null @@ -1,55 +0,0 @@ -Package: legisTaiwan -Type: Package -Title: An Interface to Access Taiwan Legislative API in R -Version: 0.2.1 -Authors@R: c(person("Yen-Chieh", "Liao", email = "davidycliao@gmail.com", role = c("aut", "cre")), - person("Li", "Tang", email = "li.tang@reading.ac.uk", role = c("ctb", "aut")), - person("Taiwan Legislative Yuan 立法院", role = c("cph", "fnd")), - 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. -Maintainer: Yen-Chieh Liao -Depends: R (>= 3.4.0) -License: GPL-3 + file LICENSE -Encoding: UTF-8 -LazyData: true -Imports: - jsonlite, - attempt, - stringr, - curl, - tibble, - rvest, - withr, - httr, - utils, - readr, - dplyr, - magrittr, - ggplot2, - rlang, - plotly -Suggests: - knitr, - rmarkdown, - remotes, - tidyverse, - testthat (>= 3.0.0) -RoxygenNote: 7.3.2 -BugReports: https://github.com/davidycliao/legisTaiwan/issues -URL: https://davidycliao.github.io/legisTaiwan/ -VignetteBuilder: knitr -Roxygen: list(markdown = TRUE) -Config/testthat/edition: 3 -SystemRequirements: pandoc (>= 1.14) - http://pandoc.org -Config/build/clean-inst-doc: FALSE -Config/build/clean-check-dir: FALSE -Config/build/ignore-non-ascii: TRUE -Config/default/Rcheck/ignore-ascii: TRUE -Config/default/Rcheck/ascii: FALSE -Config/default/Rcheck/incoming: FALSE -NeedsCompilation: no -Config/rextendr/rextendr.rchk.force: false -AS-CRAN: FALSE diff --git a/.Rproj.user/763C8F27/sources/per/t/92AB474C b/.Rproj.user/763C8F27/sources/per/t/92AB474C deleted file mode 100644 index ee8a7815..00000000 --- a/.Rproj.user/763C8F27/sources/per/t/92AB474C +++ /dev/null @@ -1,29 +0,0 @@ -{ - "id": "92AB474C", - "path": "~/Dropbox/My Packages/legisTaiwan/README.Rmd", - "project_path": "README.Rmd", - "type": "r_markdown", - "hash": "3353744613", - "contents": "", - "dirty": false, - "created": 1735991848069.0, - "source_on_save": false, - "relative_order": 4, - "properties": { - "source_window_id": "", - "Source": "Source", - "cursorPosition": "122,0", - "scrollLine": "106", - "rmdVisualMode": "false", - "rmdVisualCollapsedChunks": "", - "rmdVisualModeLocation": "2:0" - }, - "folds": "", - "lastKnownWriteTime": 1736024309, - "encoding": "UTF-8", - "collab_server": "", - "source_window": "", - "last_content_update": 1736024309640, - "read_only": false, - "read_only_alternatives": [] -} \ No newline at end of file diff --git a/.Rproj.user/763C8F27/sources/per/t/92AB474C-contents b/.Rproj.user/763C8F27/sources/per/t/92AB474C-contents deleted file mode 100644 index b040dc86..00000000 --- a/.Rproj.user/763C8F27/sources/per/t/92AB474C-contents +++ /dev/null @@ -1,132 +0,0 @@ ---- -output: github_document -always_allow_html: true ---- - - - - -## Real-time and Archives of Taiwan Legislative Data in R - - - -[![codecov](https://codecov.io/gh/davidycliao/legisTaiwan/branch/master/graph/badge.svg?token=HVVTCOE90D)](https://codecov.io/gh/davidycliao/legisTaiwan) -[![R-CMD-check](https://github.com/davidycliao/legisTaiwan/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/davidycliao/legisTaiwan/actions/workflows/R-CMD-check.yaml) -[![Test -coverage](https://github.com/davidycliao/legisTaiwan/actions/workflows/test-coverage.yaml/badge.svg)](https://github.com/davidycliao/legisTaiwan/actions/workflows/test-coverage.yaml) -[![pkgdown](https://github.com/davidycliao/legisTaiwan/actions/workflows/pkgdown.yaml/badge.svg)](https://github.com/davidycliao/legisTaiwan/actions/workflows/pkgdown.yaml) -[![CodeFactor](https://www.codefactor.io/repository/github/davidycliao/legistaiwan/badge)](https://www.codefactor.io/repository/github/davidycliao/legistaiwan) -[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.7633962.svg)](https://doi.org/10.5281/zenodo.7633962) - - - - -```{r, include = FALSE} -knitr::opts_chunk$set( - collapse = TRUE, - comment = "#>", - fig.path = "man/figures/", - out.width = "100%" -) -``` - - - - - - - - -
-`legisTaiwan` is designed to streamline access to real-time archives of Taiwan's legislative data, drawing inspiration from the UK's TheyWorkForYou API. By providing straightforward access to the Taiwan Legislative Yuan API in R, this package not only aims to enhance legislative accountability and public transparency but also serves as a powerful tool for academic research. Scholars can easily retrieve and analyze legislative data including voting records, parliamentary questions, and bill proposals, facilitating quantitative research and empirical analysis. As the package interfaces directly with Legislative Yuan API endpoints, a stable internet connection is required. Users are welcome to contact the author for any API implementation assistance. -
- - -
-`legisTaiwan` 套件旨在簡化台灣立法院資料的即時存取,其設計理念來自於英國的 TheyWorkForYou API。透過在 R 環境中提供直接連接立法院開放資料 API 的便捷管道,本套件不僅致力於提升立法問責制和公共透明度,更為學術研究者提供了系統化分析立法數據的工具。研究人員可以輕鬆獲取並分析立法委員的表決紀錄、問政質詢、法案提案等資料,有助於量化研究和實證分析。由於套件需要直接與立法院 API 介接,使用時請確保網路連線穩定。如有任何 API 使用上的問題,歡迎與套件作者聯繫。 -
- - -
- - - -### Get Started with Using [`remotes`](https://github.com/r-lib/remotes): - -``` r -install.packages("remotes") -remotes::install_github("davidycliao/legisTaiwan", force = TRUE) -``` - -``` -library(legisTaiwan) -#> ## legisTaiwan ## -#> ## An R package connecting to the Taiwan Legislative API. ## -``` - - -### Summary Descriptive of Taiwan Legilative Yuan API - -```{r include=FALSE} -library(legisTaiwan) - -``` - -```{r include=FALSE} -stats <- get_tly_stat() -``` - -__Legislative Bills Statistics__ - -```{r} -analyze_bills(stats) - -``` - -__Legislative Meeting Statistics__ - -```{r} -analyze_meetings(stats) -``` - -__Legislative Video (IVOD) Statistics__ - -```{r} -analyze_ivod(stats) -``` - - - - - - - -
- -### Important Notice: API Migration - - - -
- - - - - - - - - - -The Legislative Yuan API has transitioned from `https://ly.govapi.tw` to `https://v2.ly.govapi.tw`. While we are maintaining support for functions that use the legacy API, please note that the old API endpoint will eventually be deprecated. We recommend users to gradually transition to the newer API versions as they become available. - - -
- -
- - - - - - diff --git a/.Rproj.user/763C8F27/sources/per/t/AE90ACEE b/.Rproj.user/763C8F27/sources/per/t/AE90ACEE deleted file mode 100644 index bcc53adf..00000000 --- a/.Rproj.user/763C8F27/sources/per/t/AE90ACEE +++ /dev/null @@ -1,26 +0,0 @@ -{ - "id": "AE90ACEE", - "path": "~/Dropbox/My Packages/legisTaiwan/_pkgdown.yml", - "project_path": "_pkgdown.yml", - "type": "yaml", - "hash": "572334948", - "contents": "", - "dirty": false, - "created": 1735990445353.0, - "source_on_save": false, - "relative_order": 1, - "properties": { - "source_window_id": "", - "Source": "Source", - "cursorPosition": "91,0", - "scrollLine": "74" - }, - "folds": "", - "lastKnownWriteTime": 1736024433, - "encoding": "UTF-8", - "collab_server": "", - "source_window": "", - "last_content_update": 1736024433234, - "read_only": false, - "read_only_alternatives": [] -} \ No newline at end of file diff --git a/.Rproj.user/763C8F27/sources/per/t/AE90ACEE-contents b/.Rproj.user/763C8F27/sources/per/t/AE90ACEE-contents deleted file mode 100644 index 50f01abe..00000000 --- a/.Rproj.user/763C8F27/sources/per/t/AE90ACEE-contents +++ /dev/null @@ -1,141 +0,0 @@ -url: https://davidycliao.github.io/legisTaiwan/ - -home: - title: Accessing Real-time and Archives of Taiwan Legislative Data in R - - links: - - text: Discussion - href: https://github.com/davidycliao/legisTaiwan/discussions - - text: 立法院 API - href: https://ly.govapi.tw - - text: law-diff 提案法律對照比 - href: https://openfunltd.github.io/law-diff/?keyword=&term=11&sessionPeriod=&proposer= - - text: DATALY 立院統合資料網 - href: https://dataly.openfun.app - - text: Taiwan Citizen Congress Watch - href: https://ccw.org.tw/assess/session/45 - - text: g0v 國會松 - href: https://g0v.hackmd.io/@SA7CD7VRSp6Fcqw9CaElcQ/SJ93ZW5XR/%2FY6A2Ox-YRDS6ixtYw1BuoA%3Fview - - text: "The Centre for Artificial Intelligence in Government (CAIG)" - href: https://www.birmingham.ac.uk/research/centres-institutes/centre-for-artificial-intelligence-in-government - -reference: -- title: API Functions - desc: functions connect to Taiwan Legialtive Yuan API. -- contents: - - get_parlquestions - - get_meetings - - get_caucus_meetings - - get_executive_response - - get_public_debates - - get_speech_video - - get_committee_record - - get_bills - - get_bills_2 - - get_legislators - - get_variable_info - - review_session_info - - legis_keywords - - get_ly_bills - - get_ly_committee_meets - - get_ly_committees_type - - get_ly_interpellations - - get_ly_ivod - - get_ly_legislator_bills - - get_ly_legislator_cosign_bills - - get_ly_legislators_by_term - - get_ly_legislator_detail - - get_tly_stat - - analyze_bills - - analyze_ivod - - analyze_meetings - - calculate_bill_trends - - create_interactive_plot - - generate_report - - -authors: - Yen-Chieh Liao: - href: https://davidycliao.github.io - Li Tang: - href: https://sites.google.com/view/litang2020?pli=1 - Taiwan Legislative Yuan 立法院: - href: "https://data.ly.gov.tw/catelog.action" - html: "" - - -template: - package: tidytemplate - bootstrap: 5 - includes: - in_header: | - - params: - ganalytics: G-X85ED8P5EW - -development: - mode: auto - -navbar: - type: inverse - left: - - icon: fa-home - href: index.html - aria-label: "Home" - - icon: fa-rocket - text: Quick Start - menu: - - text: "Quick Start Guide" - href: articles/quickstart.html#get-started-with-using-remotes - - text: "Manual" - href: articles/quickstart.html#manual.html - - # - icon: fa-project-diagram - # text: Manual - # menu: - # - text: "Interpellation and Debates" - # href: articles/manual.html#interpellation-and-debates - # - text: "Bill and Budget" - # href: articles/manual.html#bill-and-budget - # - text: "Miscellaneous" - # href: articles/manual.html#miscellaneous - - - icon: fa-file-code-o - text: Reference - menu: - - text: "Function Reference" - href: reference/index.html - - - icon: fa-file-code-o - text: Tutorial - menu: - - text: "Records of the Bills" - href: articles/get_bills.html - - text: "Demographic Data" - href: articles/get_legislators.html - - text: "Parliarmentary Questions" - href: articles/get_parlquestions.html - - text: "Party Caucus Negotiation" - href: articles/get_caucus_meetings.html - - - icon: fa-newspaper-o - text: News - menu: - - text: "0.1.7" - href: news/index.html#legistaiwan-017-development-version - - text: "0.1.6" - href: news/index.html#legistaiwan-016-development-version - - text: "0.1.4" - href: news/index.html#legistaiwan-014-development-version - - text: "0.1.3" - href: news/index.html#legistaiwan-013-development-version - - text: "0.1.1" - href: news/index.html#legistaiwan-011-development-version - - right: - - icon: fa-github fa-lg - text: GitHub - href: https://github.com/davidycliao/legisTaiwan - - - diff --git a/.Rproj.user/763C8F27/sources/per/t/C9ACA1E1 b/.Rproj.user/763C8F27/sources/per/t/C9ACA1E1 deleted file mode 100644 index d734351d..00000000 --- a/.Rproj.user/763C8F27/sources/per/t/C9ACA1E1 +++ /dev/null @@ -1,26 +0,0 @@ -{ - "id": "C9ACA1E1", - "path": "~/Dropbox/My Packages/legisTaiwan/R/get_ly_stat.R", - "project_path": "R/get_ly_stat.R", - "type": "r_source", - "hash": "767761133", - "contents": "", - "dirty": false, - "created": 1736027743242.0, - "source_on_save": false, - "relative_order": 8, - "properties": { - "source_window_id": "", - "Source": "Source", - "cursorPosition": "30,0", - "scrollLine": "12" - }, - "folds": "", - "lastKnownWriteTime": 1736027504, - "encoding": "UTF-8", - "collab_server": "", - "source_window": "", - "last_content_update": 1736027504, - "read_only": false, - "read_only_alternatives": [] -} \ No newline at end of file diff --git a/.Rproj.user/763C8F27/sources/per/t/C9ACA1E1-contents b/.Rproj.user/763C8F27/sources/per/t/C9ACA1E1-contents deleted file mode 100644 index 4031f247..00000000 --- a/.Rproj.user/763C8F27/sources/per/t/C9ACA1E1-contents +++ /dev/null @@ -1,115 +0,0 @@ -#' @title Fetch and Parse Legislative Yuan Statistics -#' -#' @description -#' Retrieves statistical data from the Legislative Yuan API and parses it into a structured format. -#' The function fetches data about bills, legislators, gazettes, meetings, and IVOD records. -#' -#' @return A list containing five main components: -#' \itemize{ -#' \item bill - Statistics about legislative bills, including total count and term-wise breakdown -#' \item legislator - Information about legislators across different terms -#' \item gazette - Statistics about legislative gazettes and agendas -#' \item meet - Meeting statistics including counts and dates -#' \item ivod - Video recording statistics with date ranges -#' } -#' -#' @examples -#' \dontrun{ -#' stats <- get_tly_stat() -#' # View total number of bills -#' print(stats$bill$total) -#' # View legislator counts by term -#' print(stats$legislator$terms) -#' } -#' -#' @importFrom httr GET content status_code -#' @importFrom jsonlite fromJSON -#' @importFrom dplyr select mutate arrange desc -#' @importFrom magrittr %>% -#' @importFrom rlang .data -#' @encoding UTF-8 -#' @export -get_tly_stat <- function() { - # Send GET request to the API - response <- httr::GET("https://v2.ly.govapi.tw/stat") - - # Check if the request was successful - if (httr::status_code(response) != 200) { - stop("API request failed with status code: ", httr::status_code(response)) - } - - # Parse JSON response - content <- httr::content(response, "text", encoding = "UTF-8") - data <- jsonlite::fromJSON(content) - - # Initialize result list - result <- list() - - # 1. Bill statistics - result$bill <- list( - total = data$bill$total, - max_update_time = as.POSIXct(data$bill$max_mtime/1000, origin="1970-01-01"), - terms = data$bill$terms %>% - dplyr::select(.data$term, .data$count) %>% - dplyr::arrange(dplyr::desc(.data$term)) - ) - - # 2. Legislator statistics - result$legislator <- list( - total = data$legislator$total, - terms = data$legislator$terms %>% - dplyr::arrange(dplyr::desc(.data$term)) - ) - - # 3. Gazette statistics - result$gazette <- list( - total = data$gazette$total, - agenda_total = data$gazette$agenda_total, - last_meeting = as.POSIXct(data$gazette$max_meeting_date/1000, origin="1970-01-01"), - yearly_stats = data$gazette$comYears %>% - dplyr::mutate( - meeting_date = as.POSIXct(.data$max_meeting_date/1000, origin="1970-01-01") - ) %>% - dplyr::select(.data$year, .data$count, .data$agenda_count, .data$meeting_date) - ) - - # 4. Meeting statistics - result$meet <- list( - total = data$meet$total, - terms = data$meet$terms %>% - dplyr::mutate( - max_meeting_date = as.POSIXct(.data$max_meeting_date/1000, origin="1970-01-01") - ) %>% - dplyr::select( - .data$term, - .data$count, - .data$max_meeting_date, - .data$meetdata_count, - .data$議事錄_count - ) %>% - dplyr::arrange(dplyr::desc(.data$term)) - ) - - # 5. IVOD (video) statistics - result$ivod <- list( - total = data$ivod$total, - date_range = list( - start = as.POSIXct(data$ivod$min_meeting_date/1000, origin="1970-01-01"), - end = as.POSIXct(data$ivod$max_meeting_date/1000, origin="1970-01-01") - ), - terms = data$ivod$terms %>% - dplyr::mutate( - start_date = as.POSIXct(.data$min_meeting_date/1000, origin="1970-01-01"), - end_date = as.POSIXct(.data$max_meeting_date/1000, origin="1970-01-01") - ) %>% - dplyr::select( - .data$term, - .data$count, - .data$start_date, - .data$end_date - ) %>% - dplyr::arrange(dplyr::desc(.data$term)) - ) - - return(result) -} diff --git a/.Rproj.user/763C8F27/sources/per/t/E6CE64AC b/.Rproj.user/763C8F27/sources/per/t/E6CE64AC deleted file mode 100644 index 48d4b502..00000000 --- a/.Rproj.user/763C8F27/sources/per/t/E6CE64AC +++ /dev/null @@ -1,26 +0,0 @@ -{ - "id": "E6CE64AC", - "path": "~/Dropbox/My Packages/legisTaiwan/R/info.R", - "project_path": "R/info.R", - "type": "r_source", - "hash": "4092324700", - "contents": "", - "dirty": false, - "created": 1736027747775.0, - "source_on_save": false, - "relative_order": 9, - "properties": { - "source_window_id": "", - "Source": "Source", - "cursorPosition": "191,0", - "scrollLine": "195" - }, - "folds": "", - "lastKnownWriteTime": 1735269660, - "encoding": "UTF-8", - "collab_server": "", - "source_window": "", - "last_content_update": 1735269660, - "read_only": false, - "read_only_alternatives": [] -} \ No newline at end of file diff --git a/.Rproj.user/763C8F27/sources/prop/023A30B2 b/.Rproj.user/763C8F27/sources/prop/023A30B2 index 6dbe7bde..11ca7c45 100644 --- a/.Rproj.user/763C8F27/sources/prop/023A30B2 +++ b/.Rproj.user/763C8F27/sources/prop/023A30B2 @@ -1,6 +1,6 @@ { "source_window_id": "", "Source": "Source", - "cursorPosition": "10,0", + "cursorPosition": "11,0", "scrollLine": "0" } \ No newline at end of file diff --git a/.Rproj.user/763C8F27/sources/prop/15233BD7 b/.Rproj.user/763C8F27/sources/prop/15233BD7 index c2f8b6a1..0743276c 100644 --- a/.Rproj.user/763C8F27/sources/prop/15233BD7 +++ b/.Rproj.user/763C8F27/sources/prop/15233BD7 @@ -1,6 +1,6 @@ { "source_window_id": "", "Source": "Source", - "cursorPosition": "67,10", - "scrollLine": "0" + "cursorPosition": "1,0", + "scrollLine": "6" } \ No newline at end of file diff --git a/.Rproj.user/763C8F27/sources/prop/55451CD2 b/.Rproj.user/763C8F27/sources/prop/55451CD2 index 5bfd0dfb..01ad40ce 100644 --- a/.Rproj.user/763C8F27/sources/prop/55451CD2 +++ b/.Rproj.user/763C8F27/sources/prop/55451CD2 @@ -1,6 +1,6 @@ { "source_window_id": "", "Source": "Source", - "cursorPosition": "85,10", - "scrollLine": "56" + "cursorPosition": "0,102", + "scrollLine": "0" } \ No newline at end of file diff --git a/.Rproj.user/763C8F27/sources/prop/5CAD1E2F b/.Rproj.user/763C8F27/sources/prop/5CAD1E2F index 1c892914..105d6301 100644 --- a/.Rproj.user/763C8F27/sources/prop/5CAD1E2F +++ b/.Rproj.user/763C8F27/sources/prop/5CAD1E2F @@ -1,6 +1,6 @@ { "source_window_id": "", "Source": "Source", - "cursorPosition": "52,0", - "scrollLine": "0" + "cursorPosition": "122,0", + "scrollLine": "118" } \ No newline at end of file diff --git a/.Rproj.user/763C8F27/sources/prop/6AB6A820 b/.Rproj.user/763C8F27/sources/prop/6AB6A820 index 617cc45f..b0b6f13b 100644 --- a/.Rproj.user/763C8F27/sources/prop/6AB6A820 +++ b/.Rproj.user/763C8F27/sources/prop/6AB6A820 @@ -1,6 +1,6 @@ { "source_window_id": "", "Source": "Source", - "cursorPosition": "0,21", + "cursorPosition": "78,0", "scrollLine": "0" } \ No newline at end of file diff --git a/.Rproj.user/763C8F27/sources/prop/7436917F b/.Rproj.user/763C8F27/sources/prop/7436917F index 0d123cbf..f420eda3 100644 --- a/.Rproj.user/763C8F27/sources/prop/7436917F +++ b/.Rproj.user/763C8F27/sources/prop/7436917F @@ -1,6 +1,6 @@ { "source_window_id": "", "Source": "Source", - "cursorPosition": "54,0", - "scrollLine": "38" + "cursorPosition": "0,66", + "scrollLine": "0" } \ No newline at end of file diff --git a/.Rproj.user/763C8F27/sources/prop/777CDD25 b/.Rproj.user/763C8F27/sources/prop/777CDD25 index 6dbe7bde..a9a21799 100644 --- a/.Rproj.user/763C8F27/sources/prop/777CDD25 +++ b/.Rproj.user/763C8F27/sources/prop/777CDD25 @@ -1,6 +1,6 @@ { "source_window_id": "", "Source": "Source", - "cursorPosition": "10,0", - "scrollLine": "0" + "cursorPosition": "29,0", + "scrollLine": "8" } \ No newline at end of file diff --git a/.Rproj.user/763C8F27/sources/prop/7A33FC4C b/.Rproj.user/763C8F27/sources/prop/7A33FC4C index 0d3b5d54..d0ef5a82 100644 --- a/.Rproj.user/763C8F27/sources/prop/7A33FC4C +++ b/.Rproj.user/763C8F27/sources/prop/7A33FC4C @@ -2,6 +2,6 @@ "tempName": "Untitled1", "source_window_id": "", "Source": "Source", - "cursorPosition": "78,0", - "scrollLine": "58" + "cursorPosition": "2,64", + "scrollLine": "0" } \ No newline at end of file diff --git a/.Rproj.user/763C8F27/sources/prop/884D4207 b/.Rproj.user/763C8F27/sources/prop/884D4207 index 7ee3a23d..b5eb5617 100644 --- a/.Rproj.user/763C8F27/sources/prop/884D4207 +++ b/.Rproj.user/763C8F27/sources/prop/884D4207 @@ -2,6 +2,6 @@ "tempName": "Untitled2", "source_window_id": "", "Source": "Source", - "cursorPosition": "41,0", - "scrollLine": "1" + "cursorPosition": "0,56", + "scrollLine": "0" } \ No newline at end of file diff --git a/.Rproj.user/763C8F27/sources/prop/89BA0F7B b/.Rproj.user/763C8F27/sources/prop/89BA0F7B index b4dddd53..a75ae561 100644 --- a/.Rproj.user/763C8F27/sources/prop/89BA0F7B +++ b/.Rproj.user/763C8F27/sources/prop/89BA0F7B @@ -1,8 +1,8 @@ { "source_window_id": "", "Source": "Source", - "cursorPosition": "0,0", - "scrollLine": "0", + "cursorPosition": "871,0", + "scrollLine": "864", "docOutlineVisible": "1", "docOutlineSize": "133" } \ No newline at end of file diff --git a/.Rproj.user/763C8F27/sources/prop/8DB96273 b/.Rproj.user/763C8F27/sources/prop/8DB96273 index 27e87608..37383358 100644 --- a/.Rproj.user/763C8F27/sources/prop/8DB96273 +++ b/.Rproj.user/763C8F27/sources/prop/8DB96273 @@ -2,6 +2,6 @@ "tempName": "Untitled1", "source_window_id": "", "Source": "Source", - "cursorPosition": "18,47", + "cursorPosition": "0,54", "scrollLine": "0" } \ No newline at end of file diff --git a/.Rproj.user/763C8F27/sources/prop/9DFFCB24 b/.Rproj.user/763C8F27/sources/prop/9DFFCB24 index ba693f35..534ab581 100644 --- a/.Rproj.user/763C8F27/sources/prop/9DFFCB24 +++ b/.Rproj.user/763C8F27/sources/prop/9DFFCB24 @@ -1,6 +1,6 @@ { "source_window_id": "", "Source": "Source", - "cursorPosition": "233,0", - "scrollLine": "225" + "cursorPosition": "0,50", + "scrollLine": "52" } \ No newline at end of file diff --git a/.Rproj.user/763C8F27/sources/prop/BBA15AFC b/.Rproj.user/763C8F27/sources/prop/BBA15AFC index bfa056fd..f31e6b3d 100644 --- a/.Rproj.user/763C8F27/sources/prop/BBA15AFC +++ b/.Rproj.user/763C8F27/sources/prop/BBA15AFC @@ -1,6 +1,6 @@ { "source_window_id": "", "Source": "Source", - "cursorPosition": "191,0", - "scrollLine": "195" + "cursorPosition": "0,41", + "scrollLine": "3" } \ No newline at end of file diff --git a/.Rproj.user/763C8F27/sources/prop/BD0F88A4 b/.Rproj.user/763C8F27/sources/prop/BD0F88A4 index 86e5d80a..c5c08cdf 100644 --- a/.Rproj.user/763C8F27/sources/prop/BD0F88A4 +++ b/.Rproj.user/763C8F27/sources/prop/BD0F88A4 @@ -1,6 +1,6 @@ { "source_window_id": "", "Source": "Source", - "cursorPosition": "210,0", - "scrollLine": "181" + "cursorPosition": "0,61", + "scrollLine": "0" } \ No newline at end of file diff --git a/.Rproj.user/763C8F27/sources/prop/C3758EE8 b/.Rproj.user/763C8F27/sources/prop/C3758EE8 index 7305cf74..51253e20 100644 --- a/.Rproj.user/763C8F27/sources/prop/C3758EE8 +++ b/.Rproj.user/763C8F27/sources/prop/C3758EE8 @@ -2,6 +2,6 @@ "tempName": "Untitled1", "source_window_id": "", "Source": "Source", - "cursorPosition": "89,2", - "scrollLine": "3" + "cursorPosition": "2,43", + "scrollLine": "0" } \ No newline at end of file diff --git a/.Rproj.user/763C8F27/sources/prop/C5FFA97C b/.Rproj.user/763C8F27/sources/prop/C5FFA97C index 421141e8..749edcc7 100644 --- a/.Rproj.user/763C8F27/sources/prop/C5FFA97C +++ b/.Rproj.user/763C8F27/sources/prop/C5FFA97C @@ -1,6 +1,6 @@ { "source_window_id": "", "Source": "Source", - "cursorPosition": "0,0", + "cursorPosition": "2,67", "scrollLine": "0" } \ No newline at end of file diff --git a/.Rproj.user/763C8F27/sources/prop/C7EAE541 b/.Rproj.user/763C8F27/sources/prop/C7EAE541 index b6d8b08f..d6fd4704 100644 --- a/.Rproj.user/763C8F27/sources/prop/C7EAE541 +++ b/.Rproj.user/763C8F27/sources/prop/C7EAE541 @@ -1,10 +1,11 @@ { "source_window_id": "", "Source": "Source", - "cursorPosition": "50,0", - "scrollLine": "41", + "cursorPosition": "102,0", + "scrollLine": "90", "rmdVisualMode": "false", "rmdVisualCollapsedChunks": "", "rmdVisualModeLocation": "2:0", - "docOutlineVisible": "1" + "docOutlineVisible": "1", + "docOutlineSize": "276" } \ No newline at end of file diff --git a/.Rproj.user/763C8F27/sources/prop/CD7A53F9 b/.Rproj.user/763C8F27/sources/prop/CD7A53F9 index e1678e62..e61639d6 100644 --- a/.Rproj.user/763C8F27/sources/prop/CD7A53F9 +++ b/.Rproj.user/763C8F27/sources/prop/CD7A53F9 @@ -2,6 +2,6 @@ "tempName": "Untitled1", "source_window_id": "", "Source": "Source", - "cursorPosition": "74,0", - "scrollLine": "48" + "cursorPosition": "2,57", + "scrollLine": "1" } \ No newline at end of file diff --git a/.Rproj.user/763C8F27/sources/prop/D4DABFE1 b/.Rproj.user/763C8F27/sources/prop/D4DABFE1 index 421141e8..c916654d 100644 --- a/.Rproj.user/763C8F27/sources/prop/D4DABFE1 +++ b/.Rproj.user/763C8F27/sources/prop/D4DABFE1 @@ -1,6 +1,6 @@ { "source_window_id": "", "Source": "Source", - "cursorPosition": "0,0", + "cursorPosition": "0,63", "scrollLine": "0" } \ No newline at end of file diff --git a/.Rproj.user/763C8F27/sources/prop/DFE1904A b/.Rproj.user/763C8F27/sources/prop/DFE1904A index 981c386a..e0362422 100644 --- a/.Rproj.user/763C8F27/sources/prop/DFE1904A +++ b/.Rproj.user/763C8F27/sources/prop/DFE1904A @@ -1,8 +1,8 @@ { "source_window_id": "", "Source": "Source", - "cursorPosition": "82,107", - "scrollLine": "69", + "cursorPosition": "65,168", + "scrollLine": "59", "docOutlineVisible": "1", "docOutlineSize": "286" } \ No newline at end of file diff --git a/.Rproj.user/763C8F27/sources/prop/F2CB7519 b/.Rproj.user/763C8F27/sources/prop/F2CB7519 index 091e72bd..c0e43052 100644 --- a/.Rproj.user/763C8F27/sources/prop/F2CB7519 +++ b/.Rproj.user/763C8F27/sources/prop/F2CB7519 @@ -1,8 +1,8 @@ { "source_window_id": "", "Source": "Source", - "cursorPosition": "303,52", - "scrollLine": "293", + "cursorPosition": "160,23", + "scrollLine": "145", "docOutlineVisible": "1", "docOutlineSize": "58" } \ No newline at end of file diff --git a/.Rproj.user/763C8F27/sources/prop/FE4518BA b/.Rproj.user/763C8F27/sources/prop/FE4518BA index 1616c059..f420eda3 100644 --- a/.Rproj.user/763C8F27/sources/prop/FE4518BA +++ b/.Rproj.user/763C8F27/sources/prop/FE4518BA @@ -1,6 +1,6 @@ { "source_window_id": "", "Source": "Source", - "cursorPosition": "30,0", - "scrollLine": "12" + "cursorPosition": "0,66", + "scrollLine": "0" } \ No newline at end of file diff --git a/.Rproj.user/763C8F27/sources/session-61743cf2/A0507168 b/.Rproj.user/763C8F27/sources/session-61743cf2/A0507168 deleted file mode 100644 index 2b50aa7b..00000000 --- a/.Rproj.user/763C8F27/sources/session-61743cf2/A0507168 +++ /dev/null @@ -1,26 +0,0 @@ -{ - "id": "A0507168", - "path": "~/Dropbox/My Packages/legisTaiwan/.gitignore", - "project_path": ".gitignore", - "type": "gitignore", - "hash": "0", - "contents": "", - "dirty": false, - "created": 1736029948767.0, - "source_on_save": false, - "relative_order": 2, - "properties": { - "source_window_id": "", - "Source": "Source", - "cursorPosition": "9,0", - "scrollLine": "0" - }, - "folds": "", - "lastKnownWriteTime": 1736030009, - "encoding": "UTF-8", - "collab_server": "", - "source_window": "", - "last_content_update": 1736030009026, - "read_only": false, - "read_only_alternatives": [] -} \ No newline at end of file diff --git a/.Rproj.user/763C8F27/sources/session-61743cf2/B9596C53 b/.Rproj.user/763C8F27/sources/session-61743cf2/B9596C53 deleted file mode 100644 index 29f4b6de..00000000 --- a/.Rproj.user/763C8F27/sources/session-61743cf2/B9596C53 +++ /dev/null @@ -1,26 +0,0 @@ -{ - "id": "B9596C53", - "path": "~/Dropbox/My Packages/legisTaiwan/.Rbuildignore", - "project_path": ".Rbuildignore", - "type": "text", - "hash": "0", - "contents": "", - "dirty": false, - "created": 1736029843970.0, - "source_on_save": false, - "relative_order": 1, - "properties": { - "source_window_id": "", - "Source": "Source", - "cursorPosition": "16,0", - "scrollLine": "0" - }, - "folds": "", - "lastKnownWriteTime": 1736030012, - "encoding": "UTF-8", - "collab_server": "", - "source_window": "", - "last_content_update": 1736030012438, - "read_only": false, - "read_only_alternatives": [] -} \ No newline at end of file diff --git a/.Rproj.user/763C8F27/sources/session-61743cf2/B9596C53-contents b/.Rproj.user/763C8F27/sources/session-61743cf2/B9596C53-contents deleted file mode 100644 index 30d52b67..00000000 --- a/.Rproj.user/763C8F27/sources/session-61743cf2/B9596C53-contents +++ /dev/null @@ -1,16 +0,0 @@ -^\.github$ -^.*\.Rproj$ -^\.Rproj\.user$ -^_pkgdown\.yml$ -^docs$ -^pkgdown$ -^\.github$ -^codecov\.yml$ -^\.Rcheck$ -^.*\.utf8\.R$ -^README\.Rmd$ -^.*\.Rproj$ -^\.Rproj\.user$ -^README\.Rmd$ -^cran-comments\.md$ -^\.github$ diff --git a/.Rproj.user/763C8F27/sources/session-61743cf2/lock_file b/.Rproj.user/763C8F27/sources/session-61743cf2/lock_file deleted file mode 100644 index e69de29b..00000000 diff --git a/.Rproj.user/763C8F27/sources/session-fadbc9d6/197052BE-contents b/.Rproj.user/763C8F27/sources/session-fadbc9d6/197052BE-contents deleted file mode 100644 index 4c35a620..00000000 --- a/.Rproj.user/763C8F27/sources/session-fadbc9d6/197052BE-contents +++ /dev/null @@ -1,9 +0,0 @@ -^\.github$ -^.*\.Rproj$ -^\.Rproj\.user$ -^_pkgdown\.yml$ -^docs$ -^pkgdown$ -^\.github$ -^codecov\.yml$ -^.*\.utf8\.R$ diff --git a/.Rproj.user/763C8F27/sources/session-fadbc9d6/BC739EBB-contents b/.Rproj.user/763C8F27/sources/session-fadbc9d6/BC739EBB-contents deleted file mode 100644 index 4927fcc8..00000000 --- a/.Rproj.user/763C8F27/sources/session-fadbc9d6/BC739EBB-contents +++ /dev/null @@ -1,250 +0,0 @@ -#' Check Each Function's Manual -#' -#'@author David Liao (davidycliao@@gmail.com) -#' -#'@description `get_variable_info` generate each API's endpoint manual returned -#'from the website of Taiwan Legislative Yuan. The avalaible options is: `get_bills`, -#'`get_bills_2`, `get_meetings`, `get_caucus_meetings`, `get_speech_video` , -#'`get_public_debates`, `get_parlquestions`, `get_executive_response` and -#'`get_committee_record`. -#' -#'@param param_ characters. Must be one of options below: \describe{ -#' \item{get_bills}{get_bills: the records of the bills, see \url{https://data.ly.gov.tw/getds.action?id=6}} -#' \item{get_bills_2}{the records of legislators and the government proposals, see \url{https://data.ly.gov.tw/getds.action?id=6}} -#' \item{get_meetings}{the spoken meeting records, see \url{https://www.ly.gov.tw/Pages/List.aspx?nodeid=154}} -#' \item{get_caucus_meetings}{the meeting records of cross-caucus session, see \url{https://data.ly.gov.tw/getds.action?id=8}} -#' \item{get_speech_video}{the full video information of meetings and committees, see \url{https://data.ly.gov.tw/getds.action?id=148}} -#' \item{get_public_debates}{the records of national public debates, see \url{https://data.ly.gov.tw/getds.action?id=7}} -#' \item{get_parlquestions}{the records of parliamentary questions, see \url{https://data.ly.gov.tw/getds.action?id=6}} -#' \item{get_executive_response}{the records of the questions answered by the executives, see \url{https://data.ly.gov.tw/getds.action?id=2}} -#'} -#' -#'@return list \describe{ -#' \item{`page_info`}{information of the end point} -#' \item{`reference_url`}{the url of the page}} -#' -#'@details `get_variable_info` produces a list, which contains `page_info` and `reference_url`. -#' -#'@importFrom attempt stop_if_all -#'@importFrom jsonlite fromJSON -#'@importFrom rvest html_text2 read_html -#'@importFrom tibble as_tibble -#' -#' @export -#' -#' @seealso `review_session_info()`. -#' -#' @examples -#' \dontrun{ -#' get_variable_info("get_bills") -#' } -# get_variable_info <- function(param_) { -# check_internet() -# attempt::stop_if_all(website_availability(), isFALSE, msg = "the error from the API.") -# attempt::stop_if_all(param_, is.numeric, msg = "use string format only.") -# attempt::stop_if_all(param_, is.null, msg = "use correct funtion names.") -# attempt::stop_if(param_ , ~ length(.x) >1, msg = "only allowed to query one function.") -# if (param_ == "get_parlquestions") { -# url <- "https://data.ly.gov.tw/getds.action?id=6" -# } -# else if (param_ == "get_legislators") { -# url <- "https://data.ly.gov.tw/getds.action?id=16" -# } -# else if (param_ == "get_committee_record") { -# url <- "https://data.ly.gov.tw/getds.action?id=46" -# } -# else if (param_ == "get_executive_response") { -# url <- "https://data.ly.gov.tw/getds.action?id=2" -# } -# else if (param_ == "get_caucus_meetings") { -# url <- "https://data.ly.gov.tw/getds.action?id=8" -# } -# else if (param_ == "get_speech_video") { -# url <- "https://data.ly.gov.tw/getds.action?id=148" -# } -# else if (param_ == "get_bills_2") { -# url <- "https://data.ly.gov.tw/getds.action?id=20" -# } -# else if (param_ == "get_public_debates") { -# url <- "https://data.ly.gov.tw/getds.action?id=7" -# } -# else if (param_ %in% c("get_bills", "get_meetings")) { -# if (param_ == "get_meetings") { -# url <- "https://www.ly.gov.tw/Pages/List.aspx?nodeid=154" -# } -# else if (param_ == "get_bills") { -# url <- "https://www.ly.gov.tw/Pages/List.aspx?nodeid=153" -# } -# html_info <- rvest::html_text2(rvest::html_nodes(rvest::html_nodes(rvest::read_html(url), "*[id='form_Query']"), "div") ) -# page_info <- list(page_info = strsplit(html_info[14], split = "\n")[[1]], reference_url = url) -# return(page_info) -# } -# else { -# stop("Use correct funtion names below in character format: -# get_bills: the records of the bills -# get_bills_2: the records of legislators and the government proposals -# get_meetings: the spoken meeting records -# get_caucus_meetings: the meeting records of cross-caucus session -# get_speech_video: the full video information of meetings and committees -# get_public_debates: the records of national public debates -# get_parlquestions: the records of parliamentary questions -# get_executive_response: the records of the questions answered by the executives") -# } -# html <- rvest::html_nodes(rvest::read_html(url), "*[id='content']") -# title <- gsub("[[:space:]]", "", rvest::html_text2(rvest::html_nodes(html, "h2"))) -# -# content <- gsub("[[:space:]]", "", rvest::html_text2(rvest::html_nodes(html, "span"))) -# df <- data.frame(content[seq(1, length(content), 2 )], -# content[seq(1, length(content) + 1, 2 ) -1]) -# colnames(df) <- c(title[2], title[1]) -# df <- tibble::as_tibble(df) -# page_info <- list(page_info = df, reference_url = url) -# return(page_info) -# } - -get_variable_info <- function(param_) { - # Ensure internet and website availability - check_internet() - attempt::stop_if_not(website_availability(), msg = "the error from the API.") - - # Parameter checks - attempt::stop_if(param_, is.numeric, msg = "use string format only.") - attempt::stop_if(param_, is.null, msg = "use correct function names.") - attempt::stop_if(param_, ~ length(.x) > 1, msg = "only allowed to query one function.") - - # Dictionary for URL mapping - url_mapping <- list( - get_parlquestions = "https://data.ly.gov.tw/getds.action?id=6", - get_legislators = "https://data.ly.gov.tw/getds.action?id=16", - get_committee_record = "https://data.ly.gov.tw/getds.action?id=46", - get_executive_response = "https://data.ly.gov.tw/getds.action?id=2", - get_caucus_meetings = "https://data.ly.gov.tw/getds.action?id=8", - get_speech_video = "https://data.ly.gov.tw/getds.action?id=148", - get_bills_2 = "https://data.ly.gov.tw/getds.action?id=20", - get_public_debates = "https://data.ly.gov.tw/getds.action?id=7" - ) - if (!(param_ %in% names(url_mapping) || param_ %in% c("get_bills", "get_meetings"))) { - stop("Use correct function names below in character format: - get_bills: the records of the bills - get_bills_2: the records of legislators and the government proposals - get_meetings: the spoken meeting records - get_caucus_meetings: the meeting records of cross-caucus session - get_speech_video: the full video information of meetings and committees - get_public_debates: the records of national public debates - get_parlquestions: the records of parliamentary questions - get_executive_response: the records of the questions answered by the executives") - } - - - # Fetch URL from dictionary or process special cases - if (param_ %in% names(url_mapping)) { - url <- url_mapping[[param_]] - } else if (param_ == "get_meetings") { - url <- "https://www.ly.gov.tw/Pages/List.aspx?nodeid=154" - } else if (param_ == "get_bills") { - url <- "https://www.ly.gov.tw/Pages/List.aspx?nodeid=153" - } else { - stop("Use correct function names below in character format.") - } - - if (param_ %in% c("get_bills", "get_meetings")) { - html_info <- rvest::html_text2(rvest::html_nodes(rvest::html_nodes(rvest::read_html(url), "*[id='form_Query']"), "div")) - page_info <- list(page_info = strsplit(html_info[14], split = "\n")[[1]], reference_url = url) - return(page_info) - } - - html <- rvest::html_nodes(rvest::read_html(url), "*[id='content']") - title <- gsub("[[:space:]]", "", rvest::html_text2(rvest::html_nodes(html, "h2"))) - - content <- gsub("[[:space:]]", "", rvest::html_text2(rvest::html_nodes(html, "span"))) - df <- data.frame(content[seq(1, length(content), 2)], - content[seq(1, length(content) + 1, 2) - 1]) - colnames(df) <- c(title[2], title[1]) - df <- tibble::as_tibble(df) - page_info <- list(page_info = df, reference_url = url) - - return(page_info) -} - - -#' Check Session Periods in Each Year (Minguo Calendar) -#' -#'@author David Liao (davidycliao@@gmail.com) -#' -#'@details `review_session_info` produces a dataframe, displaying each session -#'period in year formatted in Minguo (Taiwan) calendar. -#' -#'@param term numeric -#' -#'@return dataframe -#' -#'@importFrom attempt stop_if_all -#'@importFrom rvest html_text2 read_html -#'@importFrom tibble as_tibble -#' -#' @seealso -#' Regarding Minguo calendar, please see \url{https://en.wikipedia.org/wiki/Republic_of_China_calendar}. -#' -#' @examples -#' \dontrun{ -#' review_session_info(7) -#' } - -review_session_info <- function(term) { - # Input validation - if(missing(term)) { - stop("Term parameter is required") - } - - attempt::stop_if_not(website_availability2(), - msg = "API connection error. Please check your internet connection.") - - attempt::stop_if(term, is.null, - msg = "Term cannot be NULL. Please provide a valid term number (1-11).") - - attempt::stop_if_not(term %in% 1:11, - msg = paste("Invalid term:", term, - "\nPlease provide a term number between 1 and 11.")) - - # Construct URL - url <- sprintf("https://npl.ly.gov.tw/do/www/appDate?status=0&expire=%02d&startYear=0", - as.numeric(term)) - - tryCatch({ - # Parse HTML - html_ <- rvest::html_nodes(rvest::read_html(url), - "*[class='section_wrapper']") - - # Extract titles - title <- stringr::str_split_1( - rvest::html_text2( - rvest::html_nodes(html_, "[class='tt_titlebar2']") - ), - "\t\r" - )[1:2] - - # Extract rows - odd_rows <- rvest::html_text2( - rvest::html_nodes(html_, "[class='tt_listrow_odd']") - ) - even_rows <- rvest::html_text2( - rvest::html_nodes(html_, "[class='tt_listrow_even']") - ) - - # Process data - data <- lapply( - lapply(c(odd_rows, even_rows), - function(x) stringr::str_split_1(x, "\r\r")), - function(x) gsub("[[:space:]]", "", x) - ) - - # Create dataframe - df <- do.call(rbind, data) - colnames(df) <- title - - return(tibble::as_tibble(df)) - }, - error = function(e) { - stop(paste("Error retrieving session information:", e$message)) - }) -} diff --git a/.Rproj.user/763C8F27/sources/session-fadbc9d6/lock_file b/.Rproj.user/763C8F27/sources/session-fadbc9d6/lock_file deleted file mode 100644 index e69de29b..00000000 diff --git a/.Rproj.user/shared/notebooks/5E338CCA-quickstart/1/s/chunks.json b/.Rproj.user/shared/notebooks/5E338CCA-quickstart/1/s/chunks.json index 7b7f0e63..0ef0869e 100644 --- a/.Rproj.user/shared/notebooks/5E338CCA-quickstart/1/s/chunks.json +++ b/.Rproj.user/shared/notebooks/5E338CCA-quickstart/1/s/chunks.json @@ -1 +1 @@ -{"chunk_definitions":[],"doc_write_time":1736036748} \ No newline at end of file +{"chunk_definitions":[],"doc_write_time":1737136397} \ No newline at end of file diff --git a/.Rproj.user/shared/notebooks/9551FBD9-README/1/s/chunks.json b/.Rproj.user/shared/notebooks/9551FBD9-README/1/s/chunks.json index b6d96e6b..630090d4 100644 --- a/.Rproj.user/shared/notebooks/9551FBD9-README/1/s/chunks.json +++ b/.Rproj.user/shared/notebooks/9551FBD9-README/1/s/chunks.json @@ -1 +1 @@ -{"chunk_definitions":[],"doc_write_time":1736033552} \ No newline at end of file +{"chunk_definitions":[{"row":77,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","include":false,"label":"unnamed-chunk-3","dev":"png"},"document_id":"AEA55EB7","chunk_id":"ckceol168k8k7","chunk_label":"unnamed-chunk-3"},{"row":84,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-5","dev":"png"},"document_id":"AEA55EB7","chunk_id":"cyflpclmbebmo","chunk_label":"unnamed-chunk-4"},{"row":96,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-2","dev":"png"},"document_id":"AEA55EB7","chunk_id":"c8c4kxfs18u6j","chunk_label":"unnamed-chunk-6"}],"doc_write_time":1737325975} \ No newline at end of file diff --git a/NEWS.md b/NEWS.md index d4be044a..76240c13 100644 --- a/NEWS.md +++ b/NEWS.md @@ -11,6 +11,8 @@ The Legislative Yuan API is transitioning from https://ly.govapi.tw to https://v2.ly.govapi.tw. While functions using the legacy API will continue to work for now, we recommend starting to migrate your code to use the new API endpoint. +
+ ------ # `legisTaiwan` 0.1.7 @@ -25,7 +27,11 @@ The Legislative Yuan API is transitioning from https://ly.govapi.tw to https://v # `legisTaiwan` 0.1.6 -* Corrected spelling errors and standardized terminology across function documentation. +Corrected spelling errors and standardized terminology across function documentation. + +
+ +------ # `legisTaiwan` 0.1.4 (development version) diff --git a/R/data.R b/R/data.R index ad256f5a..5c284ffd 100644 --- a/R/data.R +++ b/R/data.R @@ -1,4 +1,4 @@ -#' Taiwan Legislative Keywords for Text Analysis +#' Taiwan Legislative Keywords for Text Analysis 常用立法關鍵字 #' #' @title Legislative Keywords for Text Analysis #' @description A dataset containing common keywords used in Taiwan's legislative text analysis. diff --git a/R/get_ly_bills.R b/R/get_ly_bills.R index 9e70e6ec..97cc4437 100644 --- a/R/get_ly_bills.R +++ b/R/get_ly_bills.R @@ -1,4 +1,4 @@ -#' @title Fetch and Parse Legislative Yuan Bills +#' @title Fetch and Parse Legislative Yuan Bills 取得並解析立法院議案資料 #' #' @description #' Retrieves bill information from the Legislative Yuan API with comprehensive filter options. diff --git a/R/get_ly_committees.R b/R/get_ly_committees.R index 028b3e39..1ea95a7d 100644 --- a/R/get_ly_committees.R +++ b/R/get_ly_committees.R @@ -1,5 +1,5 @@ #' @encoding UTF-8 -#' @title Fetch Legislative Yuan Committee Meetings +#' @title Fetch Legislative Yuan Committee Meetings 取得立法院委員會會議資料 #' #' @description #' Retrieves and processes committee meeting information from the Legislative Yuan API. diff --git a/R/get_ly_committees_type.R b/R/get_ly_committees_type.R index 953d9dfd..2b12c852 100644 --- a/R/get_ly_committees_type.R +++ b/R/get_ly_committees_type.R @@ -1,4 +1,4 @@ -#' @title Fetch and Parse Legislative Yuan Committee Details, Jurisdiction and Codes +#' @title Fetch and Parse Legislative Yuan Committee Details, Jurisdiction and Codes 取得立法院委員會類別及職權範圍代碼 #' #' @description #' Retrieves detailed information about Legislative Yuan committees, diff --git a/R/get_ly_interpellations.R b/R/get_ly_interpellations.R index ef6e445a..a4d61b28 100644 --- a/R/get_ly_interpellations.R +++ b/R/get_ly_interpellations.R @@ -1,4 +1,4 @@ -#' @title Get Legislative Yuan Interpellation Records +#' @title Get Legislative Yuan Interpellation Records 取得立法院質詢紀錄 #' #' @description #' Fetches and parses interpellation records from the Legislative Yuan API. diff --git a/R/get_ly_ivod.R b/R/get_ly_ivod.R index 5e0b6b50..0c11eee8 100644 --- a/R/get_ly_ivod.R +++ b/R/get_ly_ivod.R @@ -1,8 +1,9 @@ #' Get Legislative Yuan IVOD Records #' -#' @title Fetch Legislative Yuan IVOD (Video) Records +#' @title Fetch Legislative Yuan IVOD (Video) Records 取得立法院議事轉播影片資料 #' #' @description +#' 從立法院開放資料平台擷取議事轉播系統(IVOD)的影片紀錄資料。 #' Retrieves IVOD (Internet Video on Demand) records from the Legislative Yuan API. #' Returns video records sorted by date in descending order. #' diff --git a/R/get_ly_legislator_bills.R b/R/get_ly_legislator_bills.R index 6c1f29be..e7e951b6 100644 --- a/R/get_ly_legislator_bills.R +++ b/R/get_ly_legislator_bills.R @@ -1,5 +1,6 @@ -#' Get Bill by legislator +#' Get Bill by legislator 取得立法委員提案資料 #' +#' @title Get Bill by legislator 取得立法委員提案資料 #' @description #' Retrieves comprehensive information for a specific legislator from the Legislative Yuan API. #' This includes personal details, committee assignments, educational background, and work experience. diff --git a/R/get_ly_legislator_cosign_bills.R b/R/get_ly_legislator_cosign_bills.R index 443ad640..aee5cc32 100644 --- a/R/get_ly_legislator_cosign_bills.R +++ b/R/get_ly_legislator_cosign_bills.R @@ -1,6 +1,6 @@ -#' Get Legislator's Cosigned Bills +#' Get Legislator's Cosigned Bills 取得立法委員連署法案 #' -#' @title Fetch Bills Cosigned by a Legislator +#' @title Fetch Bills Cosigned by a Legislator 取得立法委員連署法案 #' #' @description #' Retrieves bills that were cosigned by a specific legislator by term and name from the Legislative Yuan API. diff --git a/R/get_ly_legislator_detail.R b/R/get_ly_legislator_detail.R index c946e6d1..ab1e2b9f 100644 --- a/R/get_ly_legislator_detail.R +++ b/R/get_ly_legislator_detail.R @@ -1,4 +1,4 @@ -#' Get Legislative Yuan Legislator Detail +#' Get Legislative Yuan Legislator Detail 取得立法委員完整歷史資料 #' #' @title Fetch Legislator Detail Information #' diff --git a/R/get_ly_legislators_by_term.R b/R/get_ly_legislators_by_term.R index 462a1b6c..6da33950 100644 --- a/R/get_ly_legislators_by_term.R +++ b/R/get_ly_legislators_by_term.R @@ -1,6 +1,6 @@ #' Get Legislative Yuan Legislators by Term #' -#' @title Fetch Legislators List for a Specific Term +#' @title Fetch Legislators List for a Specific Term 依屆期取得立法委員名單 #' #' @description #' Retrieves a paginated list of legislators for a specific Legislative Yuan term. diff --git a/R/get_ly_stat.R b/R/get_ly_stat.R index 4031f247..babf5487 100644 --- a/R/get_ly_stat.R +++ b/R/get_ly_stat.R @@ -1,4 +1,4 @@ -#' @title Fetch and Parse Legislative Yuan Statistics +#' @title Fetch and Parse Legislative Yuan Statistics 取得並解析立法院統計資料 #' #' @description #' Retrieves statistical data from the Legislative Yuan API and parses it into a structured format. diff --git a/R/info.R b/R/info.R index 4927fcc8..9a815536 100644 --- a/R/info.R +++ b/R/info.R @@ -1,12 +1,12 @@ -#' Check Each Function's Manual +#' Check Each Function's Manual 檢查各函式說明文件 #' -#'@author David Liao (davidycliao@@gmail.com) +#'@author Yen-Chieh Liao (davidycliao@@gmail.com) #' #'@description `get_variable_info` generate each API's endpoint manual returned #'from the website of Taiwan Legislative Yuan. The avalaible options is: `get_bills`, #'`get_bills_2`, `get_meetings`, `get_caucus_meetings`, `get_speech_video` , #'`get_public_debates`, `get_parlquestions`, `get_executive_response` and -#'`get_committee_record`. +#'`get_committee_record`. 僅使用舊版 API 參數。 #' #'@param param_ characters. Must be one of options below: \describe{ #' \item{get_bills}{get_bills: the records of the bills, see \url{https://data.ly.gov.tw/getds.action?id=6}} @@ -30,78 +30,13 @@ #'@importFrom rvest html_text2 read_html #'@importFrom tibble as_tibble #' -#' @export #' #' @seealso `review_session_info()`. #' #' @examples -#' \dontrun{ -#' get_variable_info("get_bills") -#' } -# get_variable_info <- function(param_) { -# check_internet() -# attempt::stop_if_all(website_availability(), isFALSE, msg = "the error from the API.") -# attempt::stop_if_all(param_, is.numeric, msg = "use string format only.") -# attempt::stop_if_all(param_, is.null, msg = "use correct funtion names.") -# attempt::stop_if(param_ , ~ length(.x) >1, msg = "only allowed to query one function.") -# if (param_ == "get_parlquestions") { -# url <- "https://data.ly.gov.tw/getds.action?id=6" -# } -# else if (param_ == "get_legislators") { -# url <- "https://data.ly.gov.tw/getds.action?id=16" -# } -# else if (param_ == "get_committee_record") { -# url <- "https://data.ly.gov.tw/getds.action?id=46" -# } -# else if (param_ == "get_executive_response") { -# url <- "https://data.ly.gov.tw/getds.action?id=2" -# } -# else if (param_ == "get_caucus_meetings") { -# url <- "https://data.ly.gov.tw/getds.action?id=8" -# } -# else if (param_ == "get_speech_video") { -# url <- "https://data.ly.gov.tw/getds.action?id=148" -# } -# else if (param_ == "get_bills_2") { -# url <- "https://data.ly.gov.tw/getds.action?id=20" -# } -# else if (param_ == "get_public_debates") { -# url <- "https://data.ly.gov.tw/getds.action?id=7" -# } -# else if (param_ %in% c("get_bills", "get_meetings")) { -# if (param_ == "get_meetings") { -# url <- "https://www.ly.gov.tw/Pages/List.aspx?nodeid=154" -# } -# else if (param_ == "get_bills") { -# url <- "https://www.ly.gov.tw/Pages/List.aspx?nodeid=153" -# } -# html_info <- rvest::html_text2(rvest::html_nodes(rvest::html_nodes(rvest::read_html(url), "*[id='form_Query']"), "div") ) -# page_info <- list(page_info = strsplit(html_info[14], split = "\n")[[1]], reference_url = url) -# return(page_info) -# } -# else { -# stop("Use correct funtion names below in character format: -# get_bills: the records of the bills -# get_bills_2: the records of legislators and the government proposals -# get_meetings: the spoken meeting records -# get_caucus_meetings: the meeting records of cross-caucus session -# get_speech_video: the full video information of meetings and committees -# get_public_debates: the records of national public debates -# get_parlquestions: the records of parliamentary questions -# get_executive_response: the records of the questions answered by the executives") -# } -# html <- rvest::html_nodes(rvest::read_html(url), "*[id='content']") -# title <- gsub("[[:space:]]", "", rvest::html_text2(rvest::html_nodes(html, "h2"))) -# -# content <- gsub("[[:space:]]", "", rvest::html_text2(rvest::html_nodes(html, "span"))) -# df <- data.frame(content[seq(1, length(content), 2 )], -# content[seq(1, length(content) + 1, 2 ) -1]) -# colnames(df) <- c(title[2], title[1]) -# df <- tibble::as_tibble(df) -# page_info <- list(page_info = df, reference_url = url) -# return(page_info) -# } - +#' check_caucus <- get_variable_info("get_caucus_meetings") +#' check_caucus +#' @export get_variable_info <- function(param_) { # Ensure internet and website availability check_internet() @@ -167,7 +102,7 @@ get_variable_info <- function(param_) { } -#' Check Session Periods in Each Year (Minguo Calendar) +#' Check Session Periods in Each Year (Minguo Calendar) 檢查每年會期 (民國曆) #' #'@author David Liao (davidycliao@@gmail.com) #' @@ -186,10 +121,8 @@ get_variable_info <- function(param_) { #' Regarding Minguo calendar, please see \url{https://en.wikipedia.org/wiki/Republic_of_China_calendar}. #' #' @examples -#' \dontrun{ +#' # Show the session information for the 7th Legislative Yuan term periods in ROC calendar year #' review_session_info(7) -#' } - review_session_info <- function(term) { # Input validation if(missing(term)) { diff --git a/R/legislators.R b/R/legislators.R index 69a50486..9b336edc 100644 --- a/R/legislators.R +++ b/R/legislators.R @@ -1,6 +1,15 @@ #' The Legislator' Demographic Information and Background 提供委員基本資料 #' -#'@author David Liao (davidycliao@@gmail.com) +#'@author Yen-Chieh Liao (davidycliao@@gmail.com) +#' +#' @description +#' Provides access to legislators' basic demographic and background information through +#' the Legislative Yuan's V1 API interface. +#' +#' @details +#' This function retrieves comprehensive data about legislators including their +#' personal information, political background, and demographic details. The data +#' is available starting from the 2nd legislative term. #' #'@param term numeric or NULL The data is available from the 2nd term. #' @@ -50,7 +59,12 @@ #' or visit the API manual at \url{https://data.ly.gov.tw/getds.action?id=16}. #' 提供委員基本資料,最早資料可追溯至第2屆。 #' -#'@seealso +#' @examples +#' # Get data for the 9th term +#' legislators_data <- get_legislators(term = 9) +#' legislators_data +#' +#' @seealso #'`get_variable_info("get_legislators")`, `review_session_info()` get_legislators <- function(term = NULL, verbose = TRUE) { diff --git a/R/meeting.R b/R/meeting.R index f8a68f2b..151e796d 100644 --- a/R/meeting.R +++ b/R/meeting.R @@ -1,6 +1,10 @@ #' The Spoken Meeting Records 委員發言 #' -#'@author David Liao (davidycliao@@gmail.com) +#' @author Yen-Chieh Liao (davidycliao@gmail.com) +#' +#' @description +#' Provides access to legislators' spoken meeting records through +#' the Legislative Yuan's V1 API interface. #' #'@param start_date numeric Must be formatted in Minguo (Taiwan) calendar, e.g. 1090101. #' @@ -68,44 +72,6 @@ #' Regarding Minguo calendar, please see \url{https://en.wikipedia.org/wiki/Republic_of_China_calendar}. #' #'@encoding UTF-8 - -# get_meetings <- function(start_date = NULL, end_date = NULL, meeting_unit = NULL, -# verbose = TRUE) { -# check_internet() -# api_check(start_date = check_date(start_date), end_date = check_date(end_date)) -# set_api_url <- paste("https://www.ly.gov.tw/WebAPI/LegislativeSpeech.aspx?from=", -# start_date, "&to=", end_date, "&meeting_unit=", meeting_unit, "&mode=json", sep = "") -# tryCatch( -# { -# with_options(list(timeout = max(1000, getOption("timeout"))),{json_df <- jsonlite::fromJSON(set_api_url)}) -# df <- tibble::as_tibble(json_df) -# attempt::stop_if_all(nrow(df) == 0, isTRUE, msg = "The query is unavailable.") -# df["date_ad"] <- do.call("c", lapply(df$smeeting_date, transformed_date_meeting)) -# if (isTRUE(verbose)) { -# cat(" Retrieved URL: \n", set_api_url, "\n") -# cat(" Retrieved via :", meeting_unit, "\n") -# cat(" Retrieved date between:", as.character(check_date(start_date)), "and", as.character(check_date(end_date)), "\n") -# cat(" Retrieved number:", nrow(df), "\n") -# } -# list_data <- list("title" = "the spoken meeting records", -# "query_time" = Sys.time(), -# "retrieved_number" = nrow(df), -# "meeting_unit" = meeting_unit, -# "start_date_ad" = check_date(start_date), -# "end_date_ad" = check_date(end_date), -# "start_date" = start_date, -# "end_date" = end_date, -# "url" = set_api_url, -# "variable_names" = colnames(df), -# "manual_info" = "https://www.ly.gov.tw/Pages/List.aspx?nodeid=154", -# "data" = df) -# return(list_data) -# }, -# error = function(error_message) { -# message(error_message) -# } -# ) -# } get_meetings <- function(start_date = NULL, end_date = NULL, meeting_unit = NULL, verbose = TRUE) { check_internet() @@ -210,7 +176,11 @@ get_meetings <- function(start_date = NULL, end_date = NULL, meeting_unit = NULL #' The Meeting Records of Cross-caucus Session 黨團協商資訊 #' -#'@author David Liao (davidycliao@@gmail.com) +#' @author Yen-Chieh Liao (davidycliao@gmail.com) +#' +#' @description +#' Retrieves cross-caucus negotiation meeting records from the Legislative Yuan's +#' V1 API. #' #'@param start_date character Must be formatted in Minguo (ROC) calendar with three #'forward slashes between year, month and day, e.g. "106/10/20". @@ -363,8 +333,6 @@ get_caucus_meetings <- function(start_date = NULL, end_date = NULL, } -#' Video Information of Legislative Meetings and Committees -#' #' @title The Video Information of Meetings and Committees 院會及委員會之委員發言片段相關影片資訊 #' #' @description diff --git a/R/parlquestions.R b/R/parlquestions.R index 7197ebc1..de43984c 100644 --- a/R/parlquestions.R +++ b/R/parlquestions.R @@ -1,6 +1,10 @@ #' The Records of Parliamentary Questions 委員質詢事項資訊 #' -#' @author David Liao (davidycliao@@gmail.com) +#' @author Yen-Chieh Liao (davidycliao@@gmail.com) +#' +#' @description +#' Provides access to the records of parliamentary questions through +#' the Legislative Yuan's V1 API interface. #' #' @param term numeric or NULL. The default is set to NULL. 參數必須為數值。 #' @@ -31,19 +35,15 @@ #' } #' } #' } +#' #' @importFrom attempt stop_if_all #' @importFrom jsonlite fromJSON #' @importFrom withr with_options #' @export #' #' @examples -#' ## Query parliamentary questions by term. -#' ## 輸入「立委會期」下載立委質詢資料 -#' get_parlquestions(term = 10) -#' -#' ## Query parliamentary questions by term and session period. -#' ## 輸入「立委屆期」與「會期」下載立委質詢資料 -#' get_parlquestions(term = 10, session_period = 2) +#' term10 <- get_parlquestions(term = 10, session_period = 1) +#' term10 #' #' @details `get_parlquestions` produces a list, which contains `title`, #' `query_time`, `retrieved_number`, `retrieved_term`, `url`, `variable_names`, @@ -169,20 +169,24 @@ get_parlquestions <- function(term = NULL, session_period = NULL, verbose = TRUE #'The Records of Response to the Questions by the Executives 公報質詢事項行政院答復資訊 #' -#'@author David Liao (davidycliao@@gmail.com) +#' @author Yen-Chieh Liao (davidycliao@@gmail.com) #' -#'@param term integer, numeric or NULL. The default is NULL. The data is only +#' @description +#' Provides access to the records of parliamentary questions through +#' the Legislative Yuan's V1 API interface. +#' +#' @param term integer, numeric or NULL. The default is NULL. The data is only #'available from 8th term. 參數必須為數值。資料從自第8屆起,預設值為8。 #' -#'@param session_period integer, numeric or NULL. Available +#' @param session_period integer, numeric or NULL. Available #'options for the session is: 1, 2, 3, 4, 5, 6, 7, and 8. The default is set to NULL. 參數必須為數值。 #'`review_session_info()` generates each session period available option period #' in Minguo (Taiwan) calendar. #' -#'@param verbose logical, indicates whether `get_executive_response` should +#' @param verbose logical, indicates whether `get_executive_response` should #'print out detailed output when retrieving the data. The default is set to TRUE #' -#'@return list contains: \describe{ +#' @return list contains: \describe{ #' \item{`title`}{the records of the questions answered by the executives} #' \item{`query_time`}{the queried time} #' \item{`retrieved_number`}{the total number of observations} @@ -215,8 +219,8 @@ get_parlquestions <- function(term = NULL, session_period = NULL, verbose = TRUE #'@examples #' ## query the Executives' answered response by term and the session period. #' ## 輸入「立委屆期」與「會期」下載「行政院答復」 -#' get_executive_response(term = 8, session_period = 1) -#' +#' term8 <- get_executive_response(term = 8, session_period = 1) +#' term8 #'@details **`get_executive_response`** produces a list, which contains `title`, #'`query_time`, `retrieved_number`, `retrieved_term`, `url`, `variable_names`, #' `manual_info` and `data`. To retrieve the user manual and more information, please diff --git a/R/utils.R b/R/utils.R index 7bd7978d..840051c6 100644 --- a/R/utils.R +++ b/R/utils.R @@ -77,8 +77,6 @@ website_availability2 <- function(site = "https://npl.ly.gov.tw/do/www/appDate?s error = function(e) FALSE) } - - #' A Check for Internet Connectivity. #' #'@param x The default value is `curl::has_internet()`, which activate the diff --git a/README.Rmd b/README.Rmd index bc48dd8f..c32ad70d 100644 --- a/README.Rmd +++ b/README.Rmd @@ -43,7 +43,7 @@ knitr::opts_chunk$set(
-`legisTaiwan` 套件旨在簡化台灣立法院資料的即時存取,其設計理念來自於英國的 TheyWorkForYou API。透過在 R 環境中提供直接連接立法院開放資料 API 的便捷管道,本套件不僅致力於提升立法問責制和公共透明度,更為學術研究者提供了系統化分析立法數據的工具。研究人員可以輕鬆獲取並分析立法委員的表決紀錄、問政質詢、法案提案等資料,有助於量化研究和實證分析。由於套件需要直接與立法院 API 介接,使用時請確保網路連線穩定。如有任何 API 使用上的問題,歡迎與套件作者聯繫。 +`legisTaiwan` 套件旨在簡化台灣立法院資料的即時存取,其設計理念來自於英國的 [`TheyWorkForYou API`](https://www.theyworkforyou.com/api/)。透過在 R 環境中提供直接連接立法院開放資料 API 的便捷管道,本套件不僅致力於提升立法問責制和公共透明度,更為學術研究者提供了系統化分析立法數據的工具。研究人員可以輕鬆獲取並分析立法委員的表決紀錄、問政質詢、法案提案等資料,有助於量化研究和實證分析。由於套件需要直接與立法院 API 介接,使用時請確保網路連線穩定。如有任何 API 使用上的問題,歡迎與套件我們聯繫。
@@ -104,30 +104,14 @@ analyze_ivod(stats)
-### Important Notice: API Migration - - +### Notice: API Migration
- - - - - - - - - -The Legislative Yuan API has transitioned from `https://ly.govapi.tw` to `https://v2.ly.govapi.tw`. While we are maintaining support for functions that use the legacy API, please note that the old API endpoint will eventually be deprecated. We recommend users to gradually transition to the newer API versions as they become available. +The Legislative Yuan API has transitioned from `https://ly.govapi.tw` to `https://v2.ly.govapi.tw`. While we are still supporting functions that use the legacy API, please note that according to official notice, the old API endpoint will not be maintained. We recommend users to gradually transition to [the newer functions]() attached with API V2.

- - - - - diff --git a/README.md b/README.md index 7b93aadd..7af59273 100644 --- a/README.md +++ b/README.md @@ -42,10 +42,11 @@ author for any API implementation assistance. `legisTaiwan` 套件旨在簡化台灣立法院資料的即時存取,其設計理念來自於英國的 -TheyWorkForYou API。透過在 R 環境中提供直接連接立法院開放資料 API +[`TheyWorkForYou API`](https://www.theyworkforyou.com/api/)。透過在 R +環境中提供直接連接立法院開放資料 API 的便捷管道,本套件不僅致力於提升立法問責制和公共透明度,更為學術研究者提供了系統化分析立法數據的工具。研究人員可以輕鬆獲取並分析立法委員的表決紀錄、問政質詢、法案提案等資料,有助於量化研究和實證分析。由於套件需要直接與立法院 API 介接,使用時請確保網路連線穩定。如有任何 API -使用上的問題,歡迎與套件作者聯繫。 +使用上的問題,歡迎與套件我們聯繫。 @@ -70,65 +71,117 @@ remotes::install_github("davidycliao/legisTaiwan", force = TRUE) analyze_bills(stats) #> #> === Bill Statistics Summary === -#> Total Bills: 131762 -#> Last Updated: 2025-01-04 22:18:58 +#> Total Bills: 132175 +#> Last Updated: 2025-01-19 22:19:51 #> #> First Five Terms Bill Count: #> term count percentage cumulative -#> 1 11 8270 6.28 8270 -#> 2 10 43018 32.65 51288 -#> 3 9 30792 23.37 82080 -#> 4 8 26284 19.95 108364 -#> 5 7 15726 11.94 124090 +#> 1 11 8648 6.54 8648 +#> 2 10 43029 32.55 51677 +#> 3 9 30799 23.30 82476 +#> 4 8 26292 19.89 108768 +#> 5 7 15731 11.90 124499 +#> $plot ``` + + + #> + #> $summary + #> term count percentage cumulative + #> 1 11 8648 6.54 8648 + #> 2 10 43029 32.55 51677 + #> 3 9 30799 23.30 82476 + #> 4 8 26292 19.89 108768 + #> 5 7 15731 11.90 124499 + #> 6 6 7617 5.76 132116 + #> 7 5 59 0.04 132175 + **Legislative Meeting Statistics** ``` r analyze_meetings(stats) #> #> === Meeting Statistics Summary === -#> Total Meetings: 7111 +#> Total Meetings: 7128 #> #> Meeting Records Statistics by Term: #> term count max_meeting_date meetdata_count 議事錄_count minutes_ratio -#> 1 11 635 2025-01-09 00:00:00 610 417 65.67 +#> 1 11 652 2025-02-13 00:00:00 627 445 68.25 #> 2 10 2267 2024-05-17 01:00:00 2146 1602 70.67 #> 3 9 2390 2020-01-22 00:00:00 2237 1614 67.53 #> 4 8 1818 2015-12-18 00:00:00 1434 1468 80.75 #> 5 6 1 0 1 100.00 #> last_meeting_date -#> 1 2025-01-09 +#> 1 2025-02-13 #> 2 2024-05-17 #> 3 2020-01-22 #> 4 2015-12-18 #> 5 +#> $plot ``` + + + #> + #> $summary + #> term count max_meeting_date meetdata_count 議事錄_count minutes_ratio + #> 1 11 652 2025-02-13 00:00:00 627 445 68.25 + #> 2 10 2267 2024-05-17 01:00:00 2146 1602 70.67 + #> 3 9 2390 2020-01-22 00:00:00 2237 1614 67.53 + #> 4 8 1818 2015-12-18 00:00:00 1434 1468 80.75 + #> 5 6 1 0 1 100.00 + #> last_meeting_date + #> 1 2025-02-13 + #> 2 2024-05-17 + #> 3 2020-01-22 + #> 4 2015-12-18 + #> 5 + **Legislative Video (IVOD) Statistics** ``` r analyze_ivod(stats) #> #> === Video Statistics Summary === -#> Total Videos: 88986 -#> Data Period: 2005-03-14 to 2025-01-03 +#> Total Videos: 89259 +#> Data Period: 2005-03-14 to 2025-01-17 #> #> Video Statistics by Term: #> term count start_date end_date start_date_fmt -#> 1 11 9961 2024-02-05 07:00:00 2025-01-03 01:00:00 2024-02-05 +#> 1 11 10234 2024-02-05 07:00:00 2025-01-17 04:10:00 2024-02-05 #> 2 10 33852 2020-02-14 06:00:00 2024-01-09 01:00:00 2020-02-14 #> 3 9 34167 2016-02-19 01:00:00 2020-01-20 01:00:00 2016-02-19 #> 4 8 9608 2012-02-24 01:00:00 2015-12-18 01:00:00 2012-02-24 #> 5 7 1364 2008-02-29 01:00:00 2011-12-14 01:00:00 2008-02-29 #> end_date_fmt period_days avg_daily_videos -#> 1 2025-01-03 332.750 29.94 -#> 2 2024-01-09 1424.792 23.76 -#> 3 2020-01-20 1431.000 23.88 -#> 4 2015-12-18 1393.000 6.90 -#> 5 2011-12-14 1384.000 0.99 +#> 1 2025-01-17 346.8819 29.50 +#> 2 2024-01-09 1424.7917 23.76 +#> 3 2020-01-20 1431.0000 23.88 +#> 4 2015-12-18 1393.0000 6.90 +#> 5 2011-12-14 1384.0000 0.99 +#> $plot ``` + + + #> + #> $summary + #> term count start_date end_date start_date_fmt + #> 1 11 10234 2024-02-05 07:00:00 2025-01-17 04:10:00 2024-02-05 + #> 2 10 33852 2020-02-14 06:00:00 2024-01-09 01:00:00 2020-02-14 + #> 3 9 34167 2016-02-19 01:00:00 2020-01-20 01:00:00 2016-02-19 + #> 4 8 9608 2012-02-24 01:00:00 2015-12-18 01:00:00 2012-02-24 + #> 5 7 1364 2008-02-29 01:00:00 2011-12-14 01:00:00 2008-02-29 + #> 6 6 34 2005-03-23 01:00:00 2007-12-10 01:00:00 2005-03-23 + #> end_date_fmt period_days avg_daily_videos + #> 1 2025-01-17 346.8819 29.50 + #> 2 2024-01-09 1424.7917 23.76 + #> 3 2020-01-20 1431.0000 23.88 + #> 4 2015-12-18 1393.0000 6.90 + #> 5 2011-12-14 1384.0000 0.99 + #> 6 2007-12-10 992.0000 0.03 + @@ -137,40 +190,16 @@ analyze_ivod(stats)
-### Important Notice: API Migration +### Notice: API Migration
- - - - - - - - - - - - - - - - The Legislative Yuan API has transitioned from `https://ly.govapi.tw` to -`https://v2.ly.govapi.tw`. While we are maintaining support for -functions that use the legacy API, please note that the old API endpoint -will eventually be deprecated. We recommend users to gradually -transition to the newer API versions as they become available. +`https://v2.ly.govapi.tw`. While we are still supporting functions that +use the legacy API, please note that according to official notice, the +old API endpoint will not be maintained. We recommend users to gradually +transition to [the newer functions]() attached with API V2.

- - - - - - - - diff --git a/_pkgdown.yml b/_pkgdown.yml index 79d72a9f..ba5b55f5 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -20,38 +20,54 @@ home: href: https://www.birmingham.ac.uk/research/centres-institutes/centre-for-artificial-intelligence-in-government reference: -- title: API Functions - desc: functions connect to Taiwan Legialtive Yuan API. -- contents: - - get_parlquestions +- title: "API V1 - Basic Data" + desc: "Basic data retrieval functions from old Legislative Yuan API" + contents: + - starts_with("get_bills") - get_meetings + - get_committee_record + - get_legislators + +- title: "API V1 - Parliamentary Activities" + desc: "Functions for parliamentary activities from old API" + contents: + - get_parlquestions - get_caucus_meetings - get_executive_response - get_public_debates - get_speech_video - - get_committee_record - - get_bills - - get_bills_2 - - get_legislators - - get_variable_info - - review_session_info - - legis_keywords + +- title: "API V2 - Bills and Committees" + desc: "New API functions for bills and committee information" + contents: - get_ly_bills - get_ly_committee_meets - get_ly_committees_type - get_ly_interpellations - get_ly_ivod + +- title: "API V2 - Legislator Information" + desc: "New API functions for legislator-specific data" + contents: - get_ly_legislator_bills - get_ly_legislator_cosign_bills - get_ly_legislators_by_term - get_ly_legislator_detail - get_tly_stat - - analyze_bills - - analyze_ivod - - analyze_meetings - - calculate_bill_trends + +- title: "Analysis Tools" + desc: "Functions for data analysis and reporting" + contents: + - starts_with("analyze_") - generate_report + - calculate_bill_trends +- title: "Utility and Data" + desc: "Helper functions and datasets" + contents: + - get_variable_info + - review_session_info + - legis_keywords authors: Yen-Chieh Liao: @@ -105,21 +121,35 @@ navbar: - text: "Function Reference" href: reference/index.html - # - icon: fa-file-code-o - # text: Tutorial - # menu: - # - text: "Records of the Bills" - # href: articles/get_bills.html - # - text: "Demographic Data" - # href: articles/get_legislators.html - # - text: "Parliarmentary Questions" - # href: articles/get_parlquestions.html - # - text: "Party Caucus Negotiation" - # href: articles/get_caucus_meetings.html + + + - icon: fa-code + text: API Functions + menu: + - text: "API V1 - Basic Data" + desc: "Basic data retrieval functions from old Legislative Yuan API" + href: reference/index.html#api-v1-basic-data + - text: "API V1 - Parliamentary Activities" + desc: "Functions for parliamentary activities from old API" + href: reference/index.html#api-v1-parliamentary-activities + - text: "API V2 - Bills and Committees" + desc: "New API functions for bills and committee information" + href: reference/index.html#api-v2-bills-and-committees + - text: "API V2 - Legislator Information" + desc: "New API functions for legislator-specific data" + href: reference/index.html#api-v2-legislator-information + - text: "Analysis Tools" + desc: "Functions for data analysis and reporting" + href: reference/index.html#analysis-tools + - text: "Utility and Data" + desc: "Helper functions and datasets" + href: reference/index.html#utility-and-data - icon: fa-newspaper-o text: News menu: + - text: "0.2.1" + href: news/index.html#legistaiwan-021-development-version - text: "0.1.7" href: news/index.html#legistaiwan-017-development-version - text: "0.1.6" diff --git a/docs/404.html b/docs/404.html index f7ac6618..972ca296 100644 --- a/docs/404.html +++ b/docs/404.html @@ -59,10 +59,22 @@
  • Function Reference
  • +