Category Archives: code

Documentation Needed

Dark Brown Chocolate cups cakes with white powdered sugar sprinkled on cupcakes
Chocolate cup cakes

I write cooking recipes for publication. Documentation is a lot like writing recipes. Recipes are for all types of cooks, beginners and experts. Most of the documentation I find is sparse, lacking details, written for the person who wrote the code. It is hard to write directions for people who don’t know how to use or do the coding. I have been trying to expand the documentation for some Docker containers and I can’t find a new user that can tell me what is missing. I hear everything is find from experts.

Suggestions for requirements for documentation from recipes submission requirements.

Title, something instead of documentation.

Tell us about your recipe. Needs to be a little more than it is a Docker container.

Ingredients. Let people know what is needed. Software, libraries, how much memory needed. Give people an idea if they even can do the task with what system they have. Do not send people to the grocery store for a missing ingredient or to borrow a cup of sugar from a neighbor. This is really important for when people come to a half day workshop only to find out they can’t participate.

Prep method, for recipes what is needed is stove top, oven, grill, blender. What are we doing? Baking? Spinning up a web server, database. Be clearer are we frying or blending?

After clearly stating what we are doing, write out the directions. Include prep and cook time. For example it takes three hours to code this. Build time is half a day. Recipes state what occasion Holiday they are for. Also what category. Github tags make this easy, use them. Course Breakfast, lunch, Dinner. Quantity served. From these ideas Think the documentation thru to more useful documentation. Stack Overflow should not be your only documentation.

Pet Containers

Pet Containers
On git hub hackoregon/data-science-pet-containers are very useful Docker containers. Tools included are PostgreSQL, PostGIS, Anaconda and Rstudio. Add data and you are all set for exploring and developing. If you have any problems file an issue on git-hub. I am looking for what is missing from the directions.

large white dog
curious white dog

SPSS and RStudio

What if you have a lot of old data files in SPSS form and you do not have  SPSS  software. You are in luck if you have Rstudio. Current versions of Rstudio load SPSS data files without needing a special library for the task. There are libraries for this task.

To load SPSS data:

Open RStudio, on menu bar choose File, scroll to Import Data set, choose from SPSS.

A window opens to load the data.

Enter file name or url into file/url box.

Preview data in preview window. If it looks okay push the import button. And the data is loaded into Rstudio ready for use.

This is a very useful feature of RStudio.

Tables with R

People around Thanksgiving table enjoying dinner
Thanksgiving Table 11/26/2009

Cirque du Soleil Kurios show has an act where they mirror a table. It is amazing to see people upside down mirroring a table.

R   programming language has several packages for doing tables with R. Basic has a function called table. Which is good enough. Sometimes you want more. At a meeting last night someone said pander was the best package. Someone else said that they liked htmltable better. Also there is xtable and tables. tables was written by someone to be like SAS PROC TABULATE.  Many choices, pick out the one that you understand the directions and meets your publishing needs. Better depends on your point of view.

table

tables

xtable

htmltable

pander

Thanksgiving Table right side up
table right side up

Functions in R

Hug Point Oregon Coast
Hug Point Oregon Coast

Wish I was at the coast.

R does a lot with functions. Let’s start with a simple function statement. The base R has a function called function.

In the following code:

f is the objects name

x is the varible

the function x +1 goes between { }

Pretty simple

f <- function(x) {x + 1}

Take
f(4)

results

[1] 5

Write your code try other functions. It is easier to write a function in R than other languages.

Separating Data in R

I had some messy data to turn tidy. Column of data that needed to be separated into two columns. All the directions where obscure and not helpful. Try searching for a regular expression on the web.
One of the things I was puzzled over was \\.+ found out it meant gosub(). Much easier to search on. Delimiter was another puzzling thing until I realized that I could treat it the same as when I read csv files. This is the R code that worked.

library(dplyr)
library(tidyr)

tidymessydata <- (separate(messydata, State.ZIP, into = c(“State”,”Zip”), sep = ” “))

separate is a function

messydata is the data.frame and State.Zip is the column that should be two.

into is the new column names

sep is the delimiter function, space is what it was separated on. I pressed the space bar between the quotation marks.

Hopefully this is clearer than what I found for directions.

 

 

RStudio & GitHub

Last night I learned what step I was missing to use RStudio and GitHub together. When I needed to push code to GitHub I couldn’t get it to work. This worked:

First make a repository on GitHub.

Then copy the SSH code for cloning repositories.

Open RStudio,make a new project for the repository,  go to tools tab, choose version control, pick git.

Next set up the project version control

Paste the SSH clone code in RStudio box for GitHub

Then the rest happens and RStudio is linked to GitHub and you can commit, push and pull.

I am glad I finally figured this out. Going to user groups in beneficial.

Vagrant UP?

I am taking a DevOps class. We are using vagrant. Saturday I lost my box. I typed vagrant up on the command line in a terminal window and nothing happened. I was thinking it would pop up like web servers do.
The command that I was missing was vagrant ssh.  This command ssh (secure shell) into the virtual box.

vagrant provision command allows you to make changes and add things like games to your virtual box.

Useful vagrant commands:

vagrant up

vagrant provision

vagrant ssh