4
$\begingroup$

I would like to call a function from the SNA package at https://www.bioinformatics.org/groups/?group_id=546, but this doesn't work, and the email of the provider doesn't accept messages. Trying to load the package by

`<< "../mathcode//SNAmat.m"`

is answered by opening a navigation menu with the correct default mathcode. But, after typing SNA and choosing one of the choices correctly offered (SNAmat.m, SNAmat.nb, ...), this ends up by either

LinkOpen::linke: Could not find MathLink executable

or by

`LinkOpen::linke: Unknown MathLink problem encountered`

What happens here?

$\endgroup$

2 Answers 2

3
$\begingroup$

1. I'm not sure what is meant by "ExtraPackages," but my guess is the following directory in the installation directory:

FileNameJoin[{$InstallationDirectory, "AddOns", "ExtraPackages"}]
(* < pathname depends on system > *)

This is overwritten on re/installation of Mathematica I believe, so I don't consider it a safe place to install third-party packages. Authors who provide an installation app or instructions for a package put the package in the following directory:

$myPackageDirectory = (* a standard loc that Mma searches for packages *)
  FileNameJoin[{$UserAddOnsDirectory, "Applications"}]
(* < installation-dependent > *)

Another possibility on multi-user platforms might be to use FileNameJoin[{$AddOnsDirectory, "Applications"}]. On my single-user system, $AddOnsDirectory does not exist yet, so I would have to create it. (Obviously, I don't use this option.)

2. An important obstruction with the SNA package is the (directory/folder) structure of the SNA package. It does not conform to what Get expects, so it and Needs will fail to load either of the two packages contained in it. The following change to $Path enables Get and Needs to work properly:

Block[{$Path = 
   Append[$Path, (* adjust for SNA's nonstandard package structure *)
     FileNameJoin[{$myPackageDirectory,
      "SNA",
      "mathcode"}]]},
 Needs["SNAmat`"]
 ]

$myPackageDirectory is the pathname to a directory where SNA was installed. It can be the pathname I gave above or the full pathname to the ExtraPackages directory (or whatever). That's up to each user.

Note that this simpler code does not work:

Get["SNAmat`",
 Path -> FileNameJoin[{$myPackageDirectory,
    "SNA",
    "mathcode"}]]

It reads the file SNAmat.m but the package relies on SNAmat.m being in a directory in $Path, and the Path option does not change $Path.

Beware: SNA is an older package (which may be why it has a now non-standard structure). It has compiled binaries for Intel (Linux?) machines and requires Matlab to run. I have a different machine. For me loading the package stalls on Install:

Install[SNApath <> "pairelvs/pairelvsIFsh"] (* see SNAmat.m *)
(* < hangs > *)

I didn't try to port the components for multiple reasons (NMP, binaries probably run on the OP's machine, I don't have the target machine, the package lists no system requirements). Besides, I think the above takes care of all the Mathematica-related problems other than linking to this binary.

$\endgroup$
4
  • $\begingroup$ I have tried your fix-up, but it got me to the same point: filling a navigation menu (instead of loading, as usual ...). This time I filled correctly SNAmat.m (there was also an option of SNAmat.nb), and I got the message "LinkOpen::linke: Unknown MathLink problem encountered... Ididn't get the required message "If the package is correctly loaded the above line should look similar to LinkObject[../mathcode/../pairelvs/pairelvsIFsh, ... ]" $\endgroup$
    – florin
    Commented Jul 10 at 6:04
  • 1
    $\begingroup$ I don't get the LinkOpen::linke message or any other message. It's a problem with the binary not being runnable for me, I think. What I don't understand is that the OS immediately reports that the binary cannot be executed when I try it outside of Mathematica, but Mathematica hangs. That seems like a bug: it should report that the binary does not work. Have you tried recompiling the binaries? Have you tried reporting the issue to WRI (menu Help > Give Feedback...)? $\endgroup$
    – Michael E2
    Commented Jul 10 at 13:30
  • $\begingroup$ It seems they won't help me, since I don't have the "Service subscription". Meanwhile, is it possible that the problem is that I don't have Matlab installed on my computer? $\endgroup$
    – florin
    Commented Jul 11 at 7:44
  • 1
    $\begingroup$ Yep, you need Matlab. Somewhere the package says the binaries call Matlab. Good luck! $\endgroup$
    – Michael E2
    Commented Jul 11 at 14:22
1
$\begingroup$

I think you have some problems related to directory handling and file referencing in Mathematica. I just tried an example to test your setup,Here is the example:

(* Check current directory *)
currentDir = Directory[]

(* Check if "mathcode" exists in the current directory *)
subDirExists = DirectoryQ["mathcode"]

(* If not found, list contents of current directory to ensure "mathcode" is there *)
If[!subDirExists, FileNames[]]

(* Check if "mathcode" contains the expected files *)
filesInSubDir = FileNames[All, "mathcode"]

(* If the subdirectory is confirmed to exist and contains the expected files, load the specific file *)
If[subDirExists, 
  Get["mathcode/SNAmat.m"], 
  Print["Subdirectory 'mathcode' not found or does not contain expected files."]
]

(* Optionally, use full paths if relative paths are not working as expected *)
(* Get["/full/path/to/mathcode/SNAmat.m"] *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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