Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stata command: test that user-written commands are installed and updated #18

Open
luizaandrade opened this issue Jul 1, 2020 · 5 comments
Labels
new-command Outcome is a new command Stata vote Tag all vote issues with this label for filtering

Comments

@luizaandrade
Copy link
Contributor

No description provided.

@luizaandrade luizaandrade added new-command Outcome is a new command Stata labels Jul 1, 2020
@kbjarkefur kbjarkefur added the vote Tag all vote issues with this label for filtering label Jul 14, 2020
@RRMaximiliano
Copy link

I'm currently using these lines to check if the packages that I need are installed or updated:

*** Install required packages	
	local packages tabout ietoolkit winsor estout _gclsst 
		
	foreach pgks in `packages' {	
	  				
		capture which `pgks'
		
		if (_rc != 111) {
			display as text in smcl "Package {it:`pgks'} is installed"
			
			capture ado update `pgks'
			if (r(pkglist)) {
				display as text in smcl `"Package {it:`pgks'} is up to date."'
			}
		}
		
		else {
			display as error in smcl `"Package {it:`pgks'} needs to be installed from SSC in order to run this do-file;"' _newline ///
			`"This package will be automatically installed if it is found at SSC."'
			
			capture ssc install `pgks', replace
			
			if (_rc == 601) {
				display as error in smcl `"Package `pgks' is not found at SSC;"' _newline ///
				`"Please check if {it:`pgks'} is spelled correctly and whether `pgks' is indeed a user-written command."'
			}
			
			else {
				display as result in smcl `"Package `pgks' has been installed successfully"'
			}
		}
	}

Quite bulky, but I'll try to come with a dummy program for this (similar to what pacman does in R).

@kbjarkefur
Copy link
Member

This looks good. One thing that I am not sure how to deal with is version. Checking that it is the last version is neat, but not necessary exactly what you want all the time. Sometimes a replication package brake because the version of the package you have installed is too new. I think this command should include some feature to help with that, but not sure a perfect solution is possible.

@RRMaximiliano
Copy link

Agree. I tried it to look at the version installed using which and whether this can be saved into a scalar and compare it to the most updated version uploaded to SSC, but so far which doesn't return it, and didn't spend more time looking into it. I just left it to check the last version and update it if available. But you are right, when it comes to replication sometimes the most updated could break the code.

@RRMaximiliano
Copy link

RRMaximiliano commented Jul 27, 2020

Here is what I tried

*! version 0.0.1  25aug2020

	capture program drop packages 

	program define packages 

		syntax [anything] [, update]
		
		foreach pgks of local anything {
								
			capture which `pgks'
			
			if (_rc != 111) {
			
				display as result in smcl "Package {it:`pgks'} is installed"
			}
			
			// Look if the package is installed			
			else {
				
				display as error in smcl `"Package {it:`pgks'} needs to be installed from SSC in order to run this do-file;"' _newline ///
				`"This package will be automatically installed if it is found at SSC."'
				
				capture ssc install `pgks', replace
				
				if (_rc == 601) {
					display as error in smcl `"Package `pgks' is not found at SSC;"' _newline ///
					`"Please check if {it:`pgks'} is spelled correctly and whether `pgks' is indeed a user-written command."'
					
					exit
				}
				
				else {
					display as result in smcl `"Package `pgks' has been installed successfully"'
				}
			}
					
			// With the update option
			if ("`update'" != "") {
				
				capture ado update `pgks'
				
				if (r(pkglist)) {
					display as result in smcl `"Package {it:`pgks'} is up to date."'
				}
				
			}
		}
		
	end 

The syntax is quite straightforward. It has only the option update; so, for example, it can run something in this fashion:
packages esttab
packages esttab, update

And it also accepts multiple pkgs at the same:
packages esttab outreg2 asdoc

Maybe this could be of use. Let me know what you think. I still need to add returned results and maybe other options.

@kbjarkefur
Copy link
Member

kbjarkefur commented Jul 27, 2020

I still think we need to find some way to make sure that the correct version of the package is installed, but just the most recent version.

Nothing in your code is incorrect, but I am concerned that this will be seen as using this command and all your package version control issues are fixed. Which is more than we can promise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new-command Outcome is a new command Stata vote Tag all vote issues with this label for filtering
Projects
None yet
Development

No branches or pull requests

3 participants