I’ve written an article where I show how one can use the R package MCHT to implement the maximized Monte Carlo (MMC) procedure as described by Dufour (2006). This procedure is used when one wants to implement a Monte Carlo statistical test (where the distribution under the null hypothesis is generated from simulated data; see this article) but the distribution of the data generating process is not fully specified under the null hypothesis; that is, there are nuisance parameters. Dufour came up with a fascinating technique for obtaining a conservative test in this situation, and even provided proofs for its validity. (The procedure is far from perfect, though; specifically, it suffers from low power.)
Read the article to learn more about the procedure, the R implementation, and an example.