Group Abstract Group Abstract

Message Boards Message Boards

0
|
8.9K Views
|
8 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Native InstallPackage Function in Mathematica

Posted 10 years ago
POSTED BY: Rodrigo Murta
8 Replies

I think you made some good points Rodrigo. Here is my attempt at a routine along that line.

InstallMathematicaApplication::usage = 
  "InstallMathematicaApplication[\"URL\"] will download and install \
the application zip file located at the URL address into your \
$UserBaseDirectory/Applications folder. The installation path to the \
first item installed, which will usually be the application folder, \
is printed.";
SyntaxInformation[
   InstallMathematicaApplication] = {"ArgumentsPattern" -> {_}};
InstallMathematicaApplication[URLLink_String] :=
 Module[{modifiedURL, tempFile, application},
  modifiedURL = StringReplace[URLLink, "?dl=0" -> "?dl=1"];
  tempFile = URLSave[modifiedURL,
    FileNameJoin[{$UserBaseDirectory, "Applications", 
      "ApplicationDownload.zip"}]];
  application = 
   ExtractArchive[tempFile, 
     FileNameJoin[{$UserBaseDirectory, "Applications"}]][[1]];
  DeleteFile[tempFile];
  Print["Application installed at: ", application]
  ]

It is specialized to installing zip files into the `$UserBaseDirectory/Applications folder. But there is one problem with the ExtractArchive command. It will fail if any existing files exist. So one can't use it to update. As far as I'm concerned WRI should fix that, perhaps using an option. Right now I'm supplying my packages from Dropbox. If one creates a user link for a zip file, Dropbox ends it with ?dl=0. ExtractArchive will not work on that. So I change it to ?dl=1 in the routine.

Here is a test case you can try. It contains a rather worthless stub application I abandoned. So you could delete it after the test.

InstallMathematicaApplication["https://www.dropbox.com/s/\
kin3ajodnys92n8/ConicSections.zip?dl=0"]

`

POSTED BY: Rolf Mertig

Wolfram Research has set up a quite adequate method for writing and using packages or applications, but they have done a poor job of communicating it.

These should probably be called 'applications' rather than 'packages' because an application may contain several or no packages, and it can contain other components besides packages, such as documentation, style sheets, palettes and application notebooks. It is very easy for a potential user to install an application. Just send them a zip file that they unzip directly into their $UserBaseDirectory/Applications folder. That's it. Unzip and immediately use it.

I've written an extensive tutorial on writing applications at A Mathematica Style.

Hi David, tks for share your material,

I believe the main point is to simplify this operation, like what R does. Today in Mathematica as you stated, you have to:

  • 1 - Go to a website to download the file
  • 2 - Put in the right place
  • 3 - Unzip if necessary

or create your own functions to do that, that is not a simple thing for new users, or for install a package for 30 students in a class.

This could be simplified for: InstallPackage["https://github.com/zbjornson/MongoDBLink/"]

It's would be very convenient if you have to install a lot of packages, or batch update for a new version.

I would go even further and suggest a Wolfram Application Repository (WAR). So, you could submit your Package/Application to it, and install with a simples: InstallPackage["myApplication"], just like what R does.

POSTED BY: Rodrigo Murta
POSTED BY: Murray Eisenberg

Community software masses up my post. I'll try later

I believe that you can already do this within Wolfram Language. All you need to do is to build (or find) a package (a .m or .wl file) and save it to the appropriate directory. On the desktop, there is the $UserBaseDirectory that will work, although saving into the Applications folder/directory inside this directory is probably better. For the Cloud, there must be an analogous place to store packages.

You could probably write your own function, installPackage[], that will do exactly what you want to do.

I know I can create a package to do that, but the suggestion is to simplify this operation in a native way. R is very famous for it simple way to install a new package, I use it, and I miss something equivalent in WL.

POSTED BY: Rodrigo Murta
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard