Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to check for package dependencies in a DO file

    I've installed my first package from SSC, tab_chi_ and I am using the tabm command in a DO file. :-) This DO file is now incompatible with standard Stata; so when I give it to somebody else they will get an error if they don't have tab_chi installed.

    Is there a mechanism to check whether all the dependencies for a DO file are fulfilled and is there possibly a way to download the needed dependencies automatically? After all in the DO file only the command tabm occurs and not everybody will know that this command is part of the tab_chi package.

    Many thanks for you help!

  • #2
    Yes, Walter.

    Read the help for the following Stata commands:
    • which,
    • net,
    • capture.
    Downloading automatically may cause some headaches for your users, better report what's required and where to get it. Let the user decide.

    Best, Sergiy

    Comment


    • #3
      I agree (very very strongly) with Sergiy.

      In principle you need to document whatever you install, so that your users can too if they want to follow suit. There are alternatives, but as another user-programmer I don't like anything except deciding for myself what to install.

      Comment


      • #4
        Originally posted by Sergiy Radyakin View Post
        Read the help for the following Stata commands:
        ...
        • capture.
        ...
        Thanks a lot Sergiy. capture is the command which can help me: With this I can at least detect whether the command is available for the user - and then issue a message to download the containing package.

        Thanks again!

        Comment


        • #5
          Walter Dallaway in these situations I usually adding the following lines (based on Sergiy comment) to the beginning of the do file and that allow the do file to run without an error.

          Code:
          cap which tab_chi
          if _rc {
          ssc install tab_chi
          }

          Comment


          • #6
            Originally posted by Oded Mcdossi View Post
            ...in these situations I usually adding the following lines...

            Code:
            cap which tab_chi
            if _rc {
            ssc install tab_chi
            }
            You probably mean

            Code:
            cap which tabm
            if _rc {
            ssc install tab_chi
            }
            right? We need to test for the command but install the package. - Work like the beauty. :-)

            Comment


            • #7
              Originally posted by Oded Mcdossi View Post
              Walter Dallaway in these situations I usually adding the following lines (based on Sergiy comment) to the beginning of the do file and that allow the do file to run without an error.

              Code:
              cap which tab_chi
              if _rc {
              ssc install tab_chi
              }
              You might call me meticulous, but Sergiy and Nick suggested explicitly not to do this; and I agree. It should be up to the user of your do-file to decide what he/she wants to install or not. A more polite solution would be this:
              Code:
              capture : which tabm
              if (_rc) {
                  display as result in smcl `"Please install package {it:tab_chi} from SSC in order to run this do-file;"' _newline ///
                      `"you can do so by clicking this link: {stata "ssc install tab_chi":auto-install tab_chi}"'
                  exit 199
              }
              Regards
              Bela

              Comment


              • #8
                Dear Daniel Bela When I proposed the general technique I trust the user to adjust/improve it to his needs, especially when in this case that was his intention in the first place
                Originally posted by Walter Dallaway View Post
                [...] With this I can at least detect whether the command is available for the user - and then issue a message to download the containing package.

                Comment

                Working...
                X