Announcement

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

  • Dropbox | Imac-Windows 2 users| Best practice for temporary directory changes

    Hello all: I am working on a common project (with my student) off Dropbox on a Windows PC (with 3 different paths for the 3 PCs I have). My student (Emily) uses an IMac and has only one desktop. Both have different paths to our root project ./gv_includes folder in Dropbox.

    The do file below is designed to generate K-M plots and save them in a different directory in Dropbox.
    I would like to stay in the .\gv_includes folder as the working directory in stata for both of us while stepping out of this directory to save any images in a different Dropbox directory. Would like some pointers for how I could come back to the gv_includes for both of us after stepping out of the working directory to save images elsewhere. Is preserve/restore the best option that would work for both of us?

    See below for sample code I have at the moment.

    Code to set each of our working directories to gv_includes:
    Code:
    *-------------------------------------------------------------------------------
    **********----FIGURES AND TABLES FOR USCAP ABSTRACT---**************************
    *-------------------------------------------------------------------------------
    **# Set working directory---Directory agnostic now
    *--------------------------------------------------
    
        if regexm(c(os),"Mac") == 1 {
        local mypath = "/Users/emilys/Dropbox/Girish Files/gv_includes"
        }
    *-------------------------------------------------------------------------------    
        cap cd "C:\Users\Vijayalakshmi\Dropbox\Girish Files\gv_includes"
        cap cd "C:\Users\NewPC\Dropbox\Girish Files\gv_includes"
        cap cd "D:\gvenkataraman\Documents\Dropbox\Girish Files\gv_includes"
        
    qui do "p53select_phantm.doh.do" // Selects the subset for study
    count
    qui include unicoder

    Further down in the do file generating figures:
    Code:
        **#Fig2A
    *------------------
    local b germline
    local title "Germline alt. in subset with {it:TP53{sup:SH}}"
    local subset "if inlist(icc2,0)" 
    
        if regexm(c(os), "Mac") == 1 {
        include "/Users/emilys/Dropbox/gv_includes/gvkm2_nonpgm_risktablev2.1_km.do"
        }
        else if regexm(c(os), "Windows") == 1 {
        include ".\gvkm2_nonpgm_risktablev2.1_km.do"
        }
        
        if regexm(c(os), "Mac") == 1 {
        graph export "/Users/emilys/Dropbox/Project Amandeep TP53/phantm/Fig_uscap24_Fig2A.png", width (2400) height(1600) replace as(png)
        }
        else if regexm(c(os), "Windows") == 1 {
            gv p53  // Program that only I use for changing to top level directory->phantm folder to save images
        graph export ".\phantm\Fig_uscap24.png_Fig2A.png", width (2400) height(1600) replace as(png)
        }

  • #2
    I don't follow all of the code you show, especially since it -include-s other do-files that are neither shown nor explained.

    Be that as it may, I take it that the gist of your problem is that you want to temporarily change working directory, and then return to the directory you left, and the task is complicated that the pathname for that directory depends on the user's system. You would like a simple code that will work in all the systems. -preserve- and -restore- will not help you, because -restore- does not affect the working directory: it just brings back the data that was -preserve-d. This scheme will work across platforms:

    Code:
    //  STARTING OUT IN YOUR ORIGINAL WORKING DIRECTORY
    ...do stuff...
    
    // NEED TO CHANGE DIRECTORY FOR STORING GRAPHS
    local return_to_this_directory `c(pwd)'  // SAVE THE CURRENT WORKING DIRECTORY
    cd other_directory_path
    ...code to save graphs...
    ...maybe some other stuff in this other directory as well...
    
    // GO BACK TO THE ORIGINAL DIRECTORY
    cd "`return_to_this_directory'"
    ...do more stuff in the original directory...

    Comment


    • #3
      Apologies for busy-looking, non-reproducible code most of which was not germane to the question at hand. My student kept sticking the full paths with -if-/-else- statements for every -export- function and it made the do file look quite busy.

      The creturn `c(pwd)' is something that I will incorporate and should help scale back the volume of code and make it platform agnostic. Thanks again, Clyde Schechter

      Comment

      Working...
      X