Lập trình R theo hướng phòng thủ
Dr. Colin Gillespie
Jumping Rivers
.GlobalEnvls() để xem nội dungn
# hay tôi muốn
N
library() cho bạn truy cập trực tiếp vào chiếc hộp của góilibrary("dplyr") cho bạn dùng trực tiếp các hàm được export trong dplyr## 238 exported functions
getNamespaceExports("dplyr")
:: để gọi trực tiếp một hàm## Hàm filter từ dplyr
dplyr::filter
## Hàm filter()
stats::filter()
dplyr::filter()
filter() tôi sẽ nhận phiên bản nào?search() sẽ giúp bạnsearch()
# [1] ".GlobalEnv" "package:dplyr" "package:stats"
# <Other packages>
Xung đột không gian tên không chỉ phiền toái
Gói conflicted buộc bạn chọn hàm một cách tường minh
library("conflicted")
library("dplyr")
filter
#Error: [conflicted] `filter` found in 2 packages.
#Either pick the one you want with `::`
# * dplyr::filter
# * stats::filter
#Or declare a preference with `conflict_prefer()`
# * conflict_prefer("filter", "dplyr")
# * conflict_prefer("filter", "stats")
Lập trình R theo hướng phòng thủ