I want to use one function from a built in package (specifically CCompilers[] from "CCompilerDriver"`). It seems unnecessary to load in the whole package for the rest of my session, how can I do this only temporarily?

Is something like the following sufficient for this?

compilers = CCompilers[];

Or is there some kind of preferred or standard method that's more complete? I think I have something in mind which would work a bit like Block

  • $\begingroup$ OK thanks, I can use this to do what I want to. It would also be cool to have an environment like Block which loads a package only temporarily. I don't think the thread you linked answers that question. $\endgroup$ – Joe May 7 '18 at 11:05
  • 1
    $\begingroup$ In short, packages cannot be unloaded. "Unnecessary" does not seem like a good motivation to want to do this. If you explain your specific concerns, perhaps we can suggest a way to address them. So, what do you expect to gain by unloading the package? $\endgroup$ – Szabolcs May 7 '18 at 13:26
  • $\begingroup$ If you just want to prevent name pollution, then either: 1) remove the package context from $ContextPath when you're done (this does not unload) or 2) prevent adding it to the context path in the first place by loading the package using Block[{$ContextPath}, Needs["SomePackage`"]]. If you do this, you will need to use fully qualified names such as CCompileDriver`CCompilers[]. ClearAll seems like a bad idea to me, and could cause breakage much more easily than what I suggested. $\endgroup$ – Szabolcs May 7 '18 at 13:29
  • $\begingroup$ OK thanks Szabolcs, I've decided to go with your solution of 'stop worring about it' $\endgroup$ – Joe May 8 '18 at 11:09
  • $\begingroup$ You could also use Block[{$ContextPath}, Needs["CCompilerDriver`"]; CCompilerDriver`CCompilers[] ]. Just be sure to use Needs and not Get, to prevent double-loading. $\endgroup$ – Szabolcs May 8 '18 at 11:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.