An R package for querying and accessing open data from the Mindat API
News
The first version of the OpenMindat R package has been published on CRAN and can be accessed via https://cran.r-project.org/web/packages/OpenMindat/index.html
Overview
OpenMindat
is a package for retrieving and processing data from mindat.org Database through its open data API.
Mindat and University of Idaho collaborate on ‘OpenMindat’
Quick start
Install and load necessary packages
This package can be installed directly through the remotes
package:
.packages("remotes")
install::install_github("quexiang/OpenMindat") remotes
Or through devtools:
.packages("devtools")
install("devtools")
library("quexiang/OpenMindat") install_github
Or download the source code locally and install it as follows:
Download all the source codes and Open the OpenMindat.Rproj with RStudio.
Install packages
usethis
,httr
,readxl
, andjsonlite
.Currently the
OpenMindat
package can be installed from source files. Select theInstall Package
in theBuild
menu of RStudio (Ctrl + Shift + B).
Then, you can create a new file to load the dependent package, and then call the function of this package to retrieve and get the data you need from the Mindat API:
Create a New R Script (Ctrl + Shift + N).
Load the packages
OpenMindat
,usethis
,httr
,readxl
, andjsonlite
.
#install.packages("httr")
#install.packages("jsonlite")
#install.packages("usethis")
#install.packages("readxl")
#install.packages("OpenMindat")
(OpenMindat)
library(httr)
library(usethis)
library(jsonlite)
library(readxl) library
Set up API connection with your Mindat API token and use the functions
You should first get your own Mindat api token
YourToken
. (How to get your mindat API token ?)Set up your token
YourToken
#input your Mindat API token
("YourToken") #including the quotation marks mindat_connection
- You can now retrieve datasets of interest using functions in the
OpenMindat
package. Below are a few examples.
- Retrieve geomaterials records by chemical elements:
#query the geomaterials that contain all of the elements (e.g. Be, Cr):
<- geomaterials_contain_all_elems(c('Be','Cr'))
resp_materials_elms_df
#query the geomaterials that contain any of the elemnts(e.g. Be,Cr):
<- geomaterials_contain_any_elems(c('Be','Cr'))
resp_materials_elms_df
#query the geomaterials that contain all of the elemnts(e.g. Be,Cr) but without the element (e.g. H):
<- geomaterials_contain_all_but_not_elems(c('Be','Cr'),c('H'))
resp_materials_elms_df
#query the geomaterials that contain any of the elemnts(e.g. Be,Cr) but without the element (e.g. H):
<- geomaterials_contain_any_but_not_elems(c('Be','Cr'),c('H')) resp_materials_elms_df
- Retrieve geomaterials records by physical properties:
#query the geomaterials by given crystal system (e.g. Hexagonal):
<- geomaterials_crystal_system(c("Hexagonal"))
resp_materials_crystalsys_df
#query the geomaterials by given cleavagetype (e.g. Imperfect/Fair):
<- geomaterials_cleavagetype(c("Imperfect/Fair"))
resp_materials_cleav_df
#query the geomaterials whose hardness greater than a given value(e.g. 9):
<- geomaterials_hardness_gt(9)
resp_materials_hard_df
#query the geomaterials whose hardness less than a given value(e.g. 1):
<- geomaterials_hardness_lt(1)
resp_materials_hard_df
#query the geomaterials whose hardness within a range e.g.(1,1.2):
<- geomaterials_hardness_range(1,1.2)
resp_materials_hard_df
#query the mindat geomaterials by a given id, e.g.6:
<- mindat_geomaterial(id=6) resp_materials_id_df
- Retrieve geomaterials records by wildcard names and others:
<-geomaterials_search_name("Quartz")
df1<-geomaterials_name("qu_rtz")
df2<-geomaterials_name("_u_r_z")
df3<-geomaterials_name("qu*")
df4<- geomaterials_field_exists("meteoritical_code",TRUE)
df5<-mindat_geomaterial(id=3337)
df6<-geomaterials_varietyof(3337)
df7<-geomaterials_entrytype(c('2')) df8
- Retrieve geomaterials records by combined conditions:
<-geomaterials_contain_all_elems(c('Li','O'), hardness_min = 5.8, hardness_max = 6, crystal_system = "Triclinic",ima_status = "APPROVED",entrytype = 0) df
- Retrieve IMA minerals:
#query all the IMA list
<- minerals_ima_list()
df_ima_minerals
#query all the IMA list (only show the ima mame list):
<- minerals_ima_list(fields = "name")
df_ima_minerals
#query the IMA minerals by a given id e.g. 1 :
<- minerals_ima_retrieve(id =1) df_ima_minerals
- Retrieve Localities by descriptions and elements:
#query localities in a given country (e.g. China):
<- localities_list_country("China")
df_localities
#query localities that contain a given description:
<-localities_list_description("volcano")
df_volcano
#query localities contain the elements(e.g. Be,Si) withou the elements(e.g. H,Al) :
<- localities_list_elems_inc_exc(c("Be","Si"),c("H","Al")) df_loc_inc_exc
- Output the retrieved R dataframe to files:
<- geomaterials_hardness_gt(9.8,fields = "id,longid,name,ima_formula")
df (readxl)
library<- ConvertDF2JsonLD(df)
out (df,"df_geomaterials.jsonld")
saveMindatDataAs(df,"df_geomaterials.ttl")
saveMindatDataAs(df,"df_geomaterials.txt")
saveMindatDataAs(df,"df_geomaterials.csv") saveMindatDataAs
Documention of function list
An initial version of the OpenMindat
documentation is available, inclduing a function list and the description of each function, which can be called using the code below.
(package = OpenMindat) help
Bug Reports
Related Articles
Ma, X., Ralph, J., Zhang, J., Que, X., Prabhu, A., Morrison, S.M., Hazen, R.M., Wyborn, L., Lehnert, K., 2023. OpenMindat: Open and FAIR mineralogy data from the Mindat database. Geoscience Data Journal, In Press,https://doi.org/10.1002/gdj3.204
Jiyin Zhang,Xiang Que, Bhuwan Mdahikarmi,Robert M Hazen,Jolyon Ralph; Anirudh Prabhu, Shaunna M Morrison,Xiaogang Ma*, Using a 3D heat map to explore the diverse correlations among elements and mineral species, Applied Computing & Geosciences, 2024, https://doi.org/10.1016/j.acags.2024.100154