73-R工具指南20-优雅地在R中設置代理
2023-04-18 15:35:18 时间
前言
某些时候受限于网络限制,我们不得不使用ssr 等。
但是,电脑终端和R 却无法像电脑端一样,可以直接使用小猫clash 来管理:
比如R,每次都需要复制终端代理命令:
export https_proxy=http://127.0.0.1:7890;export http_proxy=http://127.0.0.1:7890;export all_proxy=socks5://127.0.0.1:7891
因此就引出今天的R包:r.proxy
使用
使用非常简单:
install.packages("r.proxy")
# install.packages("devtools")
devtools::install_github("xiayh17/r.proxy")
这个包相当于帮我们把上述的ip 赋值给了变量,并且可以输出一些关于网络代理的其他信息。
一般的代理IP 都是127.0.0.1:7890
,所以不用管直接默认就好啦:
r.proxy::proxy()
#> This maybe the first time proxy4you be load.
#> Please complete below configrations:)
#> Default setting can be accessed by Enter with nothing
#> [socks5 proxy] {Default as 127.0.0.1:7890} (address:port): 192.168.3.15:7890
#> [https proxy] {Default as 127.0.0.1:7890} (address:port):
#> [http proxy] {Default as 127.0.0.1:7890} (address:port):
#> Your setting have been save in ~/.Rproxy
#> Proxy info:
#> http://127.0.0.1:7890http://192.168.3.15:7890socks5://127.0.0.1:7890
#> check what your ip is:
#> IPv4:
#> 91.243.81.71
#>
#> Details:
#> {
#> "organization": "MoreneHost",
#> "longitude": 6.1661,
#> "timezone": "Europe/Luxembourg",
#> "isp": "MoreneHost",
#> "offset": 3600,
#> "asn": 199524,
#> "asn_organization": "G-Core Labs S.A.",
#> "country": "Luxembourg",
#> "ip": "91.243.81.71",
#> "latitude": 49.7498,
#> "continent_code": "EU",
#> "country_code": "LU"
#> }
如果不用了也可以切回来:
> r.proxy::noproxy()
Proxy was cleaned!
check what your ip is:
IPv4:
122.97.183.47
Details:
{
"organization": "China Unicom",
"longitude": 113.722,
"timezone": "Asia/Shanghai",
"isp": "China Unicom",
"offset": 28800,
"asn": 4837,
"asn_organization": "CHINA UNICOM China169 Backbone",
"country": "China",
"ip": "xxx",
"latitude": 34.7732,
"continent_code": "AS",
"country_code": "CN"
}
就是这么简单~
代理详细信息是哪里来的
#> Details:
#> {
#> "organization": "MoreneHost",
#> "longitude": 6.1661,
#> "timezone": "Europe/Luxembourg",
#> "isp": "MoreneHost",
#> "offset": 3600,
#> "asn": 199524,
#> "asn_organization": "G-Core Labs S.A.",
#> "country": "Luxembourg",
#> "ip": "91.243.81.71",
#> "latitude": 49.7498,
#> "continent_code": "EU",
#> "country_code": "LU"
#> }
有点好奇这个字典中的数据是哪里来的:
check_ip <- function() {
message("check what your ip is: ")
message("IPv4: ")
ipv4 <- curl_fetch_memory("https://api-ipv4.ip.sb/ip")
message(rawToChar(ipv4$content))
# message("IPv6: ")
message("Details: ")
det <- curl_fetch_memory("https://api.ip.sb/geoip")
message(jsonlite::prettify(rawToChar(det$content)))
}
其实就是https://api-ipv4.ip.sb/ip
这个网站提供了接口。
其他方法
有的小朋友可能会问。我一般设置代理其实也就是为了方便从github 上安装包呀。需要花钱配置一个代理吗?
比如你可以转到gitee 上再下载:可以直接将github上的项目先fork到自己的仓库,再复制到码云中。码云:https://gitee.com/ 实测速度很酥服。
#安装官方包‘remotes’
install.packages("remotes")
#安装官方包‘git2r’
install.packages("git2r")
remotes::install_git("https://gitee.com/mugpeng/pengToolkit.git")
今天,你学废了吗?
参考资料
[1]xiayh17/r.proxy: Set Proxy in R Console (github.com): https://github.com/xiayh17/r.proxy
相关文章
- 有两个以上苹果设备,却不知道这5个功能?你的钱白花了
- 盘点 iOS 工程 12 和安卓 9.0 相互学习了哪些特性
- 做小程序设计,不得不说的7个坑
- 这10条认知,可能就是你和大厂UI 设计师的差距
- 苹果发布iOS 12系统第七个开发者测试版
- iOS开发中runtime常用的几种方法
- 小程序洞察报告:传统品牌几大玩法、几大困惑都在这里了
- 3D成像技术来袭,金融科技将迎来哪些变革?
- 优雅快速的搭建iOS工程框架的探讨
- 拼命鼓吹5G手机的,不是傻就是坏
- 谷歌正式推出Android P第五个开发者预览版更新
- 假如安卓“无法保持免费”,谷歌能做些什么?
- iOS 内存管理:内存优化
- 谷歌“AI猜画”朋友圈刷屏:用户参与让它变得更聪明
- 一文读懂谷歌为何遭欧盟43亿欧元的创纪录罚款
- 超详细的登录注册的业务逻辑流程梳理
- 一次因代码走查引发的思维碰撞
- 手机到底是怎样泄密的?不知道的赶紧看看
- 技术变化那么快,程序员如何做到不被淘汰?
- 你可能会忽略的Git提交规范