The story I've heard about Full Metal Jacket is that Ermey was hired as a consultant because he had been a DI, and was there to coach the actor hired to play the DI.
Kubrick heard Ermey working with the guy and immediately hired Ermey for the part, and fired the other guy.
Then proceeded to tell Kubrick in no uncertain terms that the dialog that had been written for the part was absolute *expletive deleted*it, so Kubrick gave him carte blanche to come up with his own dialog on the fly.