-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path.Rhistory
512 lines (512 loc) · 13.6 KB
/
.Rhistory
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
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_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"
)
mockery::stub(get_ly_committee_meets, "httr::GET", mock_error_resp)
expect_error(
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
)
# 檢查分頁設定
expect_equal(result$metadata$current_page, 1)
expect_equal(result$metadata$per_page, 100)
# 檢查委員會類別
if(nrow(result$committees) > 0) {
expect_equal(unique(result$committees$類別), "常設委員會")
}
})
test_that("get_ly_committees_type error handling", {
# 測試錯誤參數
expect_error(
get_ly_committees_type(page = "invalid"),
"page"
)
expect_error(
get_ly_committees_type(per_page = -1),
"per_page"
)
})
# 測試錯誤參數
expect_error(
get_ly_committees_type(page = "invalid"),
"page"
)
expect_error(
get_ly_committees_type(per_page = -1),
"per_page"
)
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_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$類別), "常設委員會")
}
})
expect_error(
get_ly_committees_type(page = "invalid"),
"page"
)
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"
)
expect_error(
get_ly_committees_type(per_page = -1, show_progress = FALSE),
"API request failed with status code: 500"
)
})
expect_error(
get_ly_committees_type(page = "invalid", show_progress = FALSE),
"API request failed with status code: 500"
)
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,
name = "王金平",
show_progress = FALSE
)
# 檢查回傳值結構
expect_type(result, "list")
# 檢查必要欄位
expected_fields <- c(
"term", "name", "party",
"areaName", "partyGroup"
)
for(field in expected_fields) {
expect_true(
field %in% names(result),
info = sprintf("Field '%s' should exist in result", field)
)
}
# 檢查資料內容
expect_equal(result$term, 9)
expect_equal(result$name, "王金平")
test_that("basic functionality works", {
# 測試基本功能
result <- get_ly_legislator_detail(
term = 9,
name = "王金平",
show_progress = FALSE
)
# 檢查回傳值結構
expect_type(result, "list")
# 檢查必要欄位
expected_fields <- c(
"term", "name", "party",
"areaName", "partyGroup"
)
for(field in expected_fields) {
expect_true(
field %in% names(result),
info = sprintf("Field '%s' should exist in result", field)
)
}
# 檢查資料內容
expect_equal(result$term, 9)
expect_equal(result$name, "王金平")
})
test_that("invalid term/name combination returns error", {
expect_error(
get_ly_legislator_detail(
term = 999,
name = "不存在的立委",
show_progress = FALSE
),
"API request failed with status code: "
)
})
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)
}
}
devtools::load_all(".")
get_ly_committees_type()
x <- get_ly_committees_type()
roxygen2::roxygenise()
roxygen2::roxygenise()
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()
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()
roxygen2::roxygenise()
roxygen2::roxygenise()
library(pkgdown )
build_site()
build_site()
build_site()
roxygen2::roxygenise()
roxygen2::roxygenise()
roxygen2::roxygenise()
roxygen2::roxygenise()
build_site()
roxygen2::roxygenise()
roxygen2::roxygenise()
build_site()
deploy_to_branch()