My Coding Environment

In the course of my work with “R” on Deep Creek Lake associated projects and calculations, I find that certain programming idioms are repeated. In this note I describe briefly how I do things. I’m from the old school of programming when Fortran was the language to work with, which, today, is basically ‘functional programming.’ R suits my style and experiences.

1. Introduction

I did a lot of things with R and acquired a set of habits that are hard to break. I do try hard to keep up with what’s going on in the programming world, but not having to deal with a corporate set of rules, I do what suits me best. For example, as one develops software one’s product should really be under strict version control. A system such as GIT, is probably the way to go, but I haven’t gotten there yet. Perhaps sometime during the current process of documenting what I’ve done over the last 10 years I may actually learn it sufficiently for it to be useful.

Another example, this documentation process is done via Markdown, because it is easier to generate the appropriate HTML and publish it on the web using Hugo. I’ve resisted this for while, but now found it to be easy to work with, even though there are things that I feel are not complete.

So here I present how I do stuff.

2. Software Used

“R” is my programming language of choice. Since Fortran I’ve worked with C, C++, Python, Ruby, and now R, in that order. Python has come a long way and now features many of the same capabilities that R has.

3. File Organization

A project, such as my Deep Creek Lake project, has clearly may sub-projects or components. Figure 1 shows how I structure the work on a sub-project, component or task, whatever you want to call it.

My Coding Environment

Figure 1. Typical Structure of Programming Organization.

The main folder has the name that can identify it as a sub-project folder. All files are referenced to this location.

I put all code in the ‘code’ directory.

All input data goes into ‘data’ folder.

All results into the ‘results’ folder. These are typically outputs from the program units in the “code” folder. Sometimes results are used as input data to another program unit in the code folder.

The ‘functions’ folder contains R scripts that are generally simple functions and that are used often. Functions are included in R program units located in the ‘code’ folder. In those units they are invoked simply with this line of code:

source(../functions/credit.R)

Here “credit.R” is a function that, when called properly, will insert on a graph the script that generated it and the date of generation, something like the following example, which can be taylored:

# This function can be called with a plot to place information at the bottom of 
# the plot to provide a level of accountability as to what software created the plot.
# "script.name: is the name of the script from which this function is called."
# Sample Call: credit("credit.R")
#========1=========2=========3=========4=========5=========6=========7=========8=========9=========0
credit <- function(script.name){
# To put text on the lower right hand side of the plot (like to script name and date)
	now.date <- Sys.Date()
	script.txt <- paste("PLV: \"", script.name, "\"  ", now.date, "  ", sep="")
	mtext(script.txt, side=3,  cex=0.75, line=-1, adj=1)
}

#========1=========2=========3=========4=========5=========6=========7=========8=========9=========0

There are a number of functions that I make use of on a regular basis. All are described below in the section called “Description of my Functions”

The ‘literature’ folder collects materials from the literature that assist in solving the problem at hand. The literature can be in the form of reports, papers, books, web articles, or links.

The ‘documentation’ folder contains write-ups pertaining how I did solve the problem. These are typically done with Apple’s Pages software, but could also be done as a Markdown document or a word document or just a text file with a brief description.

The ‘references’ folder contains the documents that are referenced by the documentation in the ‘documentation’ folder.

4. A Description of My Functions

There are other functions that I use commonly. As time permits these will be written up in a separate post.



PLV
First Published: 9/4/2017