Learn R Programming

⚠️There's a newer version (1.0.1) of this package.Take me there.

OpenMindat

R package for OpenMindat

Overview

OpenMindat is a package for retrieving and processing data from 'mindat.org' Database through its open data API.

University of Idaho and 'mindat.org' collaborate on ''OpenMindat'' project.

Quick start

Install and load necessary packages

OpenMindat 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.org' API token and use the functions

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

  2. Set up your token YourToken

#input your Mindat API token
mindat_connection("YourToken") #including the quotation marks
  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)

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., 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

Copy Link

Version

Install

install.packages('OpenMindat')

Monthly Downloads

252

Version

1.0.0

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Xiang Que

Last Published

February 15th, 2024

Functions in OpenMindat (1.0.0)

geomaterials_dens_greater_than

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

retrieve the geomaterials that have the given expand.
geomaterials_field_exists

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

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

retrieve the geomaterials updated at an given time.
geomaterials_hardness_gt

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

retrieve the geomaterials that have the given fracturetype.
geomaterials_optical2v_min

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

retrieve the geomaterials by an given synid.
geomaterials_dens_range

retrieve the geomaterials whose density are within an given value.
geomaterials_dens_less_than

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

retrieve the geomaterials matched given IMA status.
geomaterials_ri_lt

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

retrieve the geomaterials that match an given lustretype.
geomaterials_contain_any_but_not_elems

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

retrieve the geomaterials whose refractive index is within an given range(gt,lt).
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_ri_gt

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

localities that contain the given txt name.
localities_list_expand

localities that contain the given expands.
geomaterials_hardness_lt

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

retrieve the geomaterials that match an given optical signs.
geomaterials_meteoritical_code

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

retrieve the geomaterials that match an given optical type.
localities_list_description

retrieve the localities that contain the given description
mindat_extract_response_body

mindat_extract_response_body
mindat_cache_delete

Delete a cached value by the users input varname
mindat_build_querystring

mindat_build_querystring
mindat_geomaterial

mindat_geomaterial
getExtension

Output the file extension of a filename
geomeaterials_ordering

retrieve the geomaterials by an given ordering.
mindat_localitiy

mindat_localitiy
localities_list_elems_exc

localities that do not contain the given elements
mindat_localities_list

mindat_localities_list
localitiy_type_retrieve

localitiy_type_retrieve
mindat_cache_has

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

locality_age
mindat_query

mindat_query
mindat_setup

mindat_setup
mindat_mineral_ima_list

mindat_mineral_ima_list
geomaterials_optical2v_max

retrieve the geomaterials that less than the given optical 2v.
geomaterials_not_contain_elems

geomaterials that do not contain the elements
geomaterials_streak

retrieve the geomaterials that match an given streak.
geomaterials_hardness_range

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

retrieve the geomaterials by a given name.
mindat_parse_raw_data

mindat_parse_raw_data
localities_list_elems_inc

localities that contain the given elements
mindat_make_data_frame

mindat_make_data_frame
mindat_mineral_ima

mindat_mineral_ima
minerals_ima_list

minerals_ima_list
saveMindatDataAs

Output file as a given format
mindat_cache_return_or_setup

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

set_api_base
minerals_ima_list_expand

minerals_ima_list_expand
geomaterials_varietyof

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

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

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

locality_age_list
localities_list_elems_inc_exc

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

Remove all cached values
localities_list_updated_at

retrieve the localities list updated at the given time.
mindat_cache_get

Get cache value
localities_retrieve_id

retrieve the localities by a given mindat id.
localities_list_all

retrieve the localities list.
localities_status_list

localities_status_list
localities_list_country

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

mindat_geomaterial_list
locality_type_list

locality_type_list
mindat_cache_set

Set cache name and value
params_to_string

params_to_string
mindat_locality_status

mindat_locality_status
minerals_ima_updated_at

retrieve the mineral_ima list updated at the given time.
mindat_locality_status_list

mindat_locality_status_list
mindat_connection

Initializing Mindat API
mindat_geomaterial_varieties

mindat_geomaterial_varieties
mindat_get_data_from_uri

mindat_get_data_from_uri
mindat_geomaterial_search

mindat_geomaterial_search
minerals_ima_list_ima

minerals_ima_list_ima
minerals_ima_retrieve

minerals_ima_retrieve
mindat_country

mindat_country
localities_status_retrieve

localities_status_retrieve
mindat_locality_type_list

mindat_locality_type_list
mindat_locality_type

mindat_locality_type
mindat_countries

mindat_countries
set_api_token

set_api_token
set_page_size

set_page_size
geomaterials_colour

geomaterials that have the given colors
geomaterials_bi_range

retrieve the geomaterials whose birifrigence are higher and lower than the given value.
OpenMindat-package

OpenMindat: Quickly Retrieve Datasets from the 'mindat.org' API
geomaterials_contain_all_but_not_elems

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

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

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

Convert a dataframe to a string of TTL format
geomaterials_by_groupid

retrieve the geomaterials by an given value of groupid.
geomaterials_cleavagetype

geomaterials that match an given cleavagetype
ConvertDF2JsonLD

Output file as a given format
geomaterials_contain_any_elems

geomaterials that contain any one of the given elements
geomaterials_contain_only_elems

geomaterials_contain_only_elems
geomaterials_contain_all_elems

geomaterials_contain_all_elems
geomaterials_entrytype

retrieve the geomaterials that have the given entrytype
geomaterials_diapheny

retrieve the geomaterials that have an given diapheny.
geomaterials_crystal_system

geomaterials that have the given crystal
geomaterials_ima

retrieve the geomaterials approved by IMA or not.
geomaterials_ima_notes

retrieve the geomaterials match given notes.