Q:

How to identify how contrasts are set in R?

I am looking for a function or code that checks how contrasts are globally set in R at any given moment, so that I can reset it after running some code. 
So I'm looking for something like this: 
# Identify current contrasts
original_contrasts <- get_contrasts() 

# Change contrasts
options(contrasts=c("contr.sum","contr.poly"))

# Run some models ....

# Reset to original contrasts
options(contrasts=original_contrasts)

Does such a function exist? 

A:

You can use options("contrasts") to store the current contrasts, which returns:
$contrasts
        unordered           ordered 
"contr.treatment"      "contr.poly" 

# Identify current contrasts
original_contrasts <- options("contrasts")

# Change contrasts
options(contrasts=c("contr.sum","contr.poly"))

The contrasts are now: 
$contrasts
[1] "contr.sum"  "contr.poly"

# Run some models ....

# Reset to original contrasts
options(contrasts=unname(unlist(original_contrasts)))

which again gives you:
$contrasts
[1] "contr.treatment" "contr.poly" 

