3
$\begingroup$

I ran into a strange problem with a function that I want to include in a package file (.m):

Cleanup[data_] := data /. (\[Placeholder] -> Missing[])

When I define this function in a notebook, and call it with some placeholders in the argument, they are replaced correctly. However, if I define this function in my package .m file, load the package, and call the function, the placeholders are not replaced. The package is automatically generated from a .nb file when saved, but the generated .m file looks ok, and manually editing doesn't help either...

An example for data would be

Cleanup[{{a, \[Placeholder]}, {b, \[Placeholder]}}]

This works fine if Cleanup is defined in a simple notebook, but if it's loaded from a .m package, nothing is replaced.

Mathematica 10.0, Win7 x64

$\endgroup$
  • $\begingroup$ Can you give us an example of the data you are trying to replace too? Is data always a list? $\endgroup$ – MarcoB Aug 11 '15 at 15:46
  • $\begingroup$ @MarcoB I added some example data - I'm using this on data tables entered in MatrixForm... $\endgroup$ – mjayvizzle Aug 11 '15 at 17:52
  • 2
    $\begingroup$ It's working ok for me when saved in a package. 10.2.0, Mac OS X x86 (64-bit) $\endgroup$ – Simon Rochester Aug 11 '15 at 18:48
3
$\begingroup$

It turns out the problem was related to the context: Apparently, the placeholder needs to be specified as

Global`\[Placeholder]

when used in a package (after BeginPackage).

$\endgroup$

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.