Learn R Programming

OpenMindat

An R package for querying and accessing open data from the Mindat API

News

When the new Mindat server is fully deployed, please connect using the default settings: mindat_connection(YourToken).

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:

install.packages("remotes")
remotes::install_github("quexiang/OpenMindat")

Or through devtools:

install.packages("devtools")
library("devtools")
install_github("quexiang/OpenMindat")

Or download the source code locally and install it as follows:

  1. Download all the source codes and Open the OpenMindat.Rproj with RStudio.

  2. Install packages usethis,httr,readxl, and jsonlite.

  3. Currently the OpenMindat package can be installed from source files. Select the Install Package in the Build 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:

  1. Create a New R Script (Ctrl + Shift + N).

  2. Load the packages OpenMindat, usethis,httr,readxl, and jsonlite.

#install.packages("httr")
#install.packages("jsonlite")
#install.packages("usethis")
#install.packages("readxl")
#install.packages("OpenMindat")
library(OpenMindat)
library(httr)
library(usethis)
library(jsonlite)
library(readxl)

Set up API connection with your Mindat API token and use the functions

  1. You should first get your own Mindat api token YourToken . (How to get your mindat API token ?)

  2. Set up your token YourToken

#input your Mindat API token
mindat_connection("YourToken") #including the quotation marks
# The new Mindat server's API is not yet fully deployed,you may need to specify the base_url 
mindat_connection("YourToken",base_url = "147.135.28.115")
  1. You can now retrieve datasets of interest using functions in the OpenMindat package. Below are a few examples.

(1) Retrieve geomaterials records by chemical elements:

#query the geomaterials that contain all of the elements (e.g. Be, Cr):
resp_materials_elms_df <- geomaterials_contain_all_elems(c('Be','Cr'))

#query the geomaterials that contain any of the elemnts(e.g. Be,Cr):
resp_materials_elms_df <- geomaterials_contain_any_elems(c('Be','Cr'))

#query the geomaterials that contain all of the elemnts(e.g. Be,Cr) but without the element (e.g. H):
resp_materials_elms_df <- geomaterials_contain_all_but_not_elems(c('Be','Cr'),c('H'))

#query the geomaterials that contain any of the elemnts(e.g. Be,Cr) but without the element (e.g. H):
resp_materials_elms_df <- geomaterials_contain_any_but_not_elems(c('Be','Cr'),c('H'))

(2) Retrieve geomaterials records by physical properties:

#query the geomaterials by given crystal system (e.g. Hexagonal):
resp_materials_crystalsys_df <- geomaterials_crystal_system(c("Hexagonal"))

#query the geomaterials by given cleavagetype (e.g. Imperfect/Fair):
resp_materials_cleav_df <- geomaterials_cleavagetype(c("Imperfect/Fair"))

#query the geomaterials whose hardness greater than a given value(e.g. 9):
resp_materials_hard_df <- geomaterials_hardness_gt(9)

#query the geomaterials whose hardness less than a given value(e.g. 1):
resp_materials_hard_df <- geomaterials_hardness_lt(1)

#query the geomaterials whose hardness within a range e.g.(1,1.2):
resp_materials_hard_df <- geomaterials_hardness_range(1,1.2)

#query the mindat geomaterials by a given id, e.g.6: 
resp_materials_id_df <- mindat_geomaterial(id=6)

(3) Retrieve geomaterials records by wildcard names and others:

df1<-geomaterials_search_name("Quartz")
df2<-geomaterials_name("qu_rtz")
df3<-geomaterials_name("_u_r_z")
df4<-geomaterials_name("qu*")
df5<- geomaterials_field_exists("meteoritical_code",TRUE)
df6<-mindat_geomaterial(id=3337)
df7<-geomaterials_varietyof(3337)
df8<-geomaterials_entrytype(c('2'))

(4) Retrieve geomaterials records by combined conditions:

df<-geomaterials_contain_all_elems(c('Li','O'), hardness_min = 5.8, hardness_max = 6, crystal_system = "Triclinic",ima_status = "APPROVED",entrytype = 0)

(5) Retrieve IMA minerals:

#query all the IMA list
df_ima_minerals <- minerals_ima_list()

#query all the IMA list (only show the ima mame list):
df_ima_minerals <- minerals_ima_list(fields = "name")

#query the IMA minerals by a given id e.g. 1 :
df_ima_minerals <- minerals_ima_retrieve(id =1)

(6) Retrieve Localities by descriptions and elements:

#query localities in a given country (e.g. China):
df_localities <- localities_list_country("China")

#query localities that contain a given description:
df_volcano<-localities_list_description("volcano")

#query localities contain the elements(e.g. Be,Si) withou the elements(e.g. H,Al) :
df_loc_inc_exc <- localities_list_elems_inc_exc(c("Be","Si"),c("H","Al"))

(7) Output the retrieved R dataframe to files:


  df <- geomaterials_hardness_gt(9.8,fields = "id,longid,name,ima_formula")
  library(readxl)
  out <- ConvertDF2JsonLD(df)
  saveMindatDataAs(df,"df_geomaterials.jsonld")
  saveMindatDataAs(df,"df_geomaterials.ttl")
  saveMindatDataAs(df,"df_geomaterials.txt")
  saveMindatDataAs(df,"df_geomaterials.csv")

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.

help(package = OpenMindat)

Technical architecture of the software package

Bug Reports

Any issues or bugs?

Related Articles

Ma, X., Ralph, J., Zhang, J., Que, X., Prabhu, A., Morrison, S.M., Hazen, R.M., Wyborn, L. and Lehnert, K., 2024. OpenMindat: Open and FAIR mineralogy data from the Mindat database. Geoscience Data Journal (SCI), 11(1), pp.94-104.[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

Acknowledgments

Copy Link

Version

Install

install.packages('OpenMindat')

Monthly Downloads

147

Version

1.0.1

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Xiang Que

Last Published

June 5th, 2025

Functions in OpenMindat (1.0.1)

Nickel_strunz10_subclasses

Nickel-strunz10-subclasses
geomaterials_bi_greater_than

retrieve the geomaterials whose birifrigence are higher than the given value.
geomaterials_diapheny

retrieve the geomaterials that have an given diapheny.
geomaterials_contain_any_but_not_elems

geomaterials that contain any of some given elements but with out any of some other given elements
geomaterials_contain_any_elems

geomaterials that contain any one of the given elements
geomaterials_bi_less_than

retrieve the geomaterials whose birifrigence are lower density than the given value.
geomaterials_contain_all_elems

geomaterials_contain_all_elems
geomaterials_hardness_range

retrieve the geomaterials whose hardness is within the given range.
geomaterials_contain_all_but_not_elems

geomaterials that contain all of some given elements but without any of some other given elements.
geomaterials_optical2v_min

retrieve the geomaterials that has higher value than the given optical 2v.
geomaterials_optical2v_max

retrieve the geomaterials that less than the given optical 2v.
OpenMindat-package

OpenMindat: Quickly Retrieve Datasets from the 'Mindat' API
geomaterials_colour

geomaterials that have the given colors
geomaterials_name

retrieve the geomaterials matched a given string in its name.
geomaterials_hardness_lt

retrieve the geomaterials whose hardness are lower than an given value.
geomaterials_ima_notes

retrieve the geomaterials match given notes.
geomaterials_ima_status

retrieve the geomaterials matched given IMA status.
geomaterials_hardness_gt

retrieve the geomaterials whose hardness are higher than an given value.
geomaterials_ri_range

retrieve the geomaterials whose refractive index is within an given range(gt,lt).
geomaterials_synid

retrieve the geomaterials by an given synid.
geomaterials_not_contain_elems

geomaterials that do not contain the elements
geomaterials_streak

retrieve the geomaterials that match an given streak.
geomaterials_cleavagetype

geomaterials that match an given cleavagetype
geomaterials_crystal_system

geomaterials that have the given crystal
localities_list_elems_inc

localities that contain the given elements
geomaterials_updated_at

retrieve the geomaterials updated at an given time.
geomaterials_dens_greater_than

retrieve the geomaterials whose density are higher than a given value.
localities_list_elems_exc

localities that do not contain the given elements
geomaterials_search_name

retrieve the geomaterials by a given name.
crystalclasses_systems

crystalclasses that match a given vector of crystal system (case-insenstive)
geomaterials_contain_only_elems

geomaterials_contain_only_elems
crystalclasses_symbols

crystalclasses that match a given vector of symbols (case-insenstive)
geomaterials_varietyof

retrieve the geomaterials that are varieties of an given id of geomaterials.
localities_list_country

retrieve the localities list that are belong to a given country.
localities_list_description

retrieve the localities that contain the given description
geomaterials_opticalsign

retrieve the geomaterials that match an given optical signs.
geomaterials_optical2v_range

retrieve the geomaterials that has the given range of optical 2v.
geomaterials_ima

retrieve the geomaterials approved by IMA or not.
geomaterials_entrytype

retrieve the geomaterials that have the given entrytype
localities_status_retrieve

localities_status_retrieve
geomaterials_field_exists

retrieve the geomaterials records of empty or not empty of a given field.
mindat_build_querystring

mindat_build_querystring
geomaterials_dens_less_than

retrieve the geomaterials whose density are lower density than a given value.
geomaterials_fracturetype

retrieve the geomaterials that have the given fracturetype.
geomaterials_lustretype

retrieve the geomaterials that match an given lustretype.
mindat_cache_return_or_setup

Check if the current environment has the cached function named varname.
locality_type_list

locality_type_list
geomaterials_meteoritical_code

retrieve the geomaterials matched a given string in its meteoritical code.
geomeaterials_non_utf

retrieve the geomaterials that include non-utf mineral names or not.
geomaterials_expand

retrieve the geomaterials that have the given expand.
mindat_locentries_lstm_id

mindat_locentries_lstm_id
mindat_cache_set

Set cache name and value
mindat_crystalclasses

mindat_crystalclasses
mindat_dana8_subgroups

mindat_dana8_subgroups
localitiy_type_retrieve

localitiy_type_retrieve
mindat_connection

Initializing Mindat API
mindat_extract_response_body

mindat_extract_response_body
mindat_locentries_retrieve

mindat_locentries_retrieve
mindat_localitiy

mindat_localitiy
geomaterials_polytypeof

retrieve the geomaterials by an given id of polytype of (the id of the mineral that this record is the polytype of. )
geomaterials_opticaltype

retrieve the geomaterials that match an given optical type.
mindat_countries

mindat_countries
localities_list_expand

localities that contain the given expands.
mindat_dana8_groups

mindat_dana8_groups
geomeaterials_ordering

retrieve the geomaterials by an given ordering.
geomaterials_ri_gt

retrieve the geomaterials that refractive index higher than an given value(gt).
localities_list_updated_at

retrieve the localities list updated at the given time.
localities_list_txt

localities that contain the given txt name.
geomaterials_ri_lt

retrieve the geomaterials that refractive index lower than an given value(lt).
mindat_locality_status_list

mindat_locality_status_list
getExtension

Output the file extension of a filename
mindat_locality_status

mindat_locality_status
locality_age

locality_age
mindat_cache_empty

Remove all cached values
localities_list_elems_inc_exc

localities that contain the given elements but not contain some other given elements.
mindat_cache_delete

Delete a cached value by the users input varname
mindat_country

mindat_country
locality_age_list

locality_age_list
mindat_geomaterial

mindat_geomaterial
mindat_query

mindat_query
mindat_locentries_list

mindat_locentries_list
mindat_crystalclass_list

mindat_crystalclass_list
mindat_nickel_strunz10_classes

mindat_nickel_strunz10_classes
mindat_locality_type_list

mindat_locality_type_list
mindat_spacegroups_list

mindat_spacegroups_list
mindat_spacegroups

mindat_spacegroups
minerals_ima_list_ima

minerals_ima_list_ima
mindat_nickel_strunz10_families

mindat_nickel_strunz10_families
localities_list_all

retrieve the localities list.
mindat_locality_type

mindat_locality_type
mindat_get_data_from_uri

mindat_get_data_from_uri
minerals_ima_retrieve

minerals_ima_retrieve
set_api_base

set_api_base
mindat_geomaterial_search

mindat_geomaterial_search
localities_retrieve_id

retrieve the localities by a given mindat id.
localities_status_list

localities_status_list
mindat_cache_get

Get cache value
saveMindatDataAs

Output file as a given format
mindat_cache_has

Check if the current environment has the cached value of varname.
mindat_geomaterial_list

mindat_geomaterial_list
mindat_geomaterial_varieties

mindat_geomaterial_varieties
mindat_localities_list

mindat_localities_list
spacegroupsets_cclass

spacegroupsets that match a given crystalclass ID (integer)
mindat_locentries_stat

mindat_locentries_stat
spacegroups_by_id

spacegroups that match a given spacegroup ID (integer)
spacegroupsets_list

return a full list of spacegroupsetsets
minerals_ima_list

minerals_ima_list
spacegroupsets_by_id

spacegroupsets that match a given spacegroupets ID (integer)
mindat_setup

mindat_setup
spacegroups_cclass

spacegroups that match a given crystalclass ID (integer)
minerals_ima_list_expand

minerals_ima_list_expand
mindat_make_data_frame

mindat_make_data_frame
spacegroupsets_sgtext

spacegroupsets that match a given sgtext (string)
mindat_nickel_strunz10_subclasses

mindat_nickel_strunz10_subclasses
mindat_parse_raw_data

mindat_parse_raw_data
mindat_mineral_ima

mindat_mineral_ima
mindat_mineral_ima_list

mindat_mineral_ima_list
mindat_spacegroupsets

mindat_spacegroupsets
minerals_ima_updated_at

retrieve the mineral_ima list updated at the given time.
set_api_token

set_api_token
mindat_spacegroupsets_list

mindat_spacegroupsets_list
params_to_string

params_to_string
set_page_size

set_page_size
spacegroups_list

return a full list of spacegroups
spacegroups_sgtext

spacegroups that match a given sgtext (string)
Nickel_strunz10_classes

Nickel-strunz10-classes
Locentries_list

retrieve a full list of locacentries.
Dana8_subgroups

dana_8 subgroups
ConvertDF2TTL

Convert a dataframe to a string of TTL format
ConvertDF2JsonLD

Output file as a given format
Locentries_retrieve

retrieve locacentries by given a Locentry ID.
Dana8_groups

dana_8 classification
Nickel_strunz10_families

Nickel-strunz10-families
Locentries_statstics_list

retrieve a full list of locacentries statstics.
Locentries_stat_retrieve

retrieve locacentries statstics by given a Locentry ID.
geomaterials_bi_range

retrieve the geomaterials whose birifrigence are higher and lower than the given value.
geomaterials_by_groupid

retrieve the geomaterials by an given value of groupid.
geomaterials_dens_range

retrieve the geomaterials whose density are within an given value.