在R中,您可以查看函数的来源,因为函数只是另一个对象.
我正在寻找一种方法来搜索这个源代码,而不知道保存源的文件.
例如,我可能想知道函数是否shapiro.test包含函数sort(它确实如此).
如果shapiro.test是字符串或字符串向量我会使用
grep('sort', shapiro.test)
Run Code Online (Sandbox Code Playgroud)
但是作为shapiro.test一个函数,这给出了错误"as.character(x)中的错误:不能强制类型'闭包'到类型'字符'的向量'".
我没有试图将函数强制转换为字符串.作为一个额外的,我不希望能够在编译时搜索基本函数.
我试图使用ggplot绘制自举样本(1000列),但结果图不正确.
这是数据:
dat<- structure(list(YY = c(1961L, 1961L, 1961L, 1961L, 1961L, 1961L,
1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L,
1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L,
1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L,
1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L,
1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L,
1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L,
1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L,
1961L, 1961L, 1961L, 1961L, 1961L, 1961L, …Run Code Online (Sandbox Code Playgroud) 我正在尝试从服务器下载栅格httr::GET.我们过去常常这样做,但是对服务器进行了一些更改,现在它不起作用.
通过浏览器或通过终端中的GET(ubuntu 16.04)使用URL工作正常并返回一个正常工作的tif栅格.但使用相同的网址httr::GET是行不通的Status: 400.
我唯一的猜测是它与数据的编码有关.但我真的不确定.
file <- paste0(tempdir(), '/file.tif')
r <-
httr::GET('https://map.ox.ac.uk/geoserver/Explorer/ows?service=WCS&version=2.0.1&request=GetCoverage&format=image/geotiff&coverageid=2015_Nature_Africa_PR&SUBSET=Long(-3,50.483779907)&SUBSET=Lat(-25.6089496609999,-11.9454326629999)&SUBSET=time(\"2015-01-01T00:00:00.000Z\")',
httr::write_disk(file, overwrite = TRUE))
ras <- raster::raster(file)
# I'm now totally confused about when and where quotes are escaped, so just to make sure...
r <-
httr::GET('https://map.ox.ac.uk/geoserver/Explorer/ows?service=WCS&version=2.0.1&request=GetCoverage&format=image/geotiff&coverageid=2015_Nature_Africa_PR&SUBSET=Long(-3,50.483779907)&SUBSET=Lat(-25.6089496609999,-11.9454326629999)&SUBSET=time("2015-01-01T00:00:00.000Z")',
httr::write_disk(file, overwrite = TRUE))
ras <- raster::raster(file)
# But just putting the url in the browser works fine.
# https://map.ox.ac.uk/geoserver/Explorer/ows?service=WCS&version=2.0.1&request=GetCoverage&format=image/geotiff&coverageid=2015_Nature_Africa_PR&SUBSET=Long(-3,50.483779907)&SUBSET=Lat(-25.6089496609999,-11.9454326629999)&SUBSET=time("2015-01-01T00:00:00.000Z")
# eg
# rr <- raster::raster('~/Desktop/2015_Nature_Africa_PR3.tif')
# And using the URL with GET in the …Run Code Online (Sandbox Code Playgroud) 我试图安装twitteR,但安装失败,说我需要httr> 0.6而我只有0.3.
我试图更新httr.但是,我似乎同时有2个版本,当我使用库(twitteR)时,它仍然说我有httr 0.3并且需要0.6(对不起我没有确切的错误消息了,并且由于这个而无法复制以下问题.)
所以,我删除了httr remove.packages('httr')(这是一个错误).
现在我无法加载devtools
> library(devtools)
Error in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]) :
there is no package called ‘httr’
Error: package or namespace load failed for ‘devtools’
Run Code Online (Sandbox Code Playgroud)
或安装包
install.packages('httr')
'''Some lines skipped'''
Error in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]) :
there is no package called ‘httr’
Error: package or namespace load failed for ‘devtools’
Execution halted
Run Code Online (Sandbox Code Playgroud)
当我尝试从tarball安装httr时,我得到与上面相同的错误消息R CMD INSTALL.
我很困惑.是时候安装干净的R了吗?
为了将来参考,我如何更新httr?