[英]How to save occurrence data from a search in rgbif
I am a new R user and I am interested in downloading a particular set of data using rgbif.我是一个新的 R 用户,我有兴趣使用 rgbif 下载一组特定的数据。 I did:
我做了:
occ_search(scientificName = "Lupinus", hasCoordinate = TRUE, continent = c('africa', 'europe', 'asia'),
basisOfRecord = "PRESERVED_SPECIMEN", decimalLatitude = '-1.50750278, 47.62390556',
decimalLongitude = '-18.75250000, 52.85138889',
fields = c('scientificName', 'decimalLatitude', 'decimalLongitude', 'country'), return = 'data')
Which works fine to do the search.这可以很好地进行搜索。 However, what I would like to do is save the search as an object to create an .csv file of it.
但是,我想要做的是将搜索保存为一个对象,以创建它的 .csv 文件。 If I go:
如果我走:
OS <- occ_search(scientificName = "Lupinus", hasCoordinate = TRUE, continent = c('africa', 'europe', 'asia'),
basisOfRecord = "PRESERVED_SPECIMEN", decimalLatitude = '-1.50750278, 47.62390556',
decimalLongitude = '-18.75250000, 52.85138889',
fields = c('scientificName', 'decimalLatitude', 'decimalLongitude', 'country'), return = 'data')
Then然后
OS1 <- as.data.frame(OS)
I get the following error:我收到以下错误:
Error in as.data.frame.default(occ) : cannot coerce class ""gbif"" to a data.frame
I also tried using occ_download
this way:我也试过这样使用
occ_download
:
OD <- occ_download("scientificName = Lupinus",
"hasCoordinate = TRUE",
"continent = africa,europe,asia",
"basisOfRecord = PRESERVED_SPECIMEN",
"decimalLatitude >= -1.50750278",
"decimalLatitude <= 47.62390556",
"decimalLongitude >= -18.75250000",
"decimalLongitude <= 52.85138889")
And all I get is a file with 0 observations and 235 columns.我得到的只是一个包含 0 个观察值和 235 列的文件。
Any help will be highly appreciated!任何帮助将不胜感激!
The reason your occ_search
output is not compatible with as.data.frame
is in the continent = c('africa', 'europe', 'asia')
argument.您的
occ_search
输出与as.data.frame
不兼容的原因是在continent = c('africa', 'europe', 'asia')
参数中。 If you look at the length(OS)
and str(OS)
, you will see that it actually has three data.frames in it.如果您查看
length(OS)
和str(OS)
,您会发现它实际上包含三个 data.frames。 You can access the individual elements like this:您可以像这样访问各个元素:
OS$europe
# or
OS['europe']
# or
OS[[1]]
You can combine these like this你可以像这样组合这些
OC1 <- rbind(OS$africa, OS$europe, OS$asia)
Or, if you are not going to know all the different names, like this:或者,如果您不打算知道所有不同的名称,如下所示:
do.call(rbind, OS)
To transform the object with class "gbif"
to a data.frame you can do OS.df <- do.call(rbind.data.frame, OS)
.要将具有
class "gbif"
的对象转换为 data.frame,您可以执行OS.df <- do.call(rbind.data.frame, OS)
。
For occ_download
you need to set a username, email and password.对于
occ_download
您需要设置用户名、电子邮件和密码。 As by gbif website (http://www.gbif.org/developer/occurrence#download) Occurrence downloads are created asynchronously - the user requests a download and, once complete, is sent and email with a link to the resulting file.正如 gbif 网站(http://www.gbif.org/developer/occurrence#download) 一样,事件下载是异步创建的 - 用户请求下载,一旦完成,就会发送并通过电子邮件发送结果文件的链接。
OD <- occ_download(user = "name", pwd = "pass", email = "e@mail.com", "scientificName = Lupinus", "hasCoordinate = TRUE", "continent = africa,europe,asia","basisOfRecord = PRESERVED_SPECIMEN","decimalLatitude >= -1.50750278","decimalLatitude <= 47.62390556","decimalLongitude >= -18.75250000","decimalLongitude <= 52.85138889")
returns an object of class gbif download
and you should receive a download link per mail or visit http://www.gbif.org/user/download to download directly.返回类
gbif download
的对象,您应该会收到每封邮件的下载链接或访问http://www.gbif.org/user/download直接下载。 This can be done through the download option at gbif.org as well.这也可以通过gbif.org 上的下载选项来完成。
<<gbif download>> Username: philipprobeck E-mail: phill@gmx.li Download key: 0078579-160910150852091
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.