Skip to content

Instantly share code, notes, and snippets.

@djouallah
Created February 22, 2019 07:53
Show Gist options
  • Save djouallah/822542e6d043148a293fde380a0cfff9 to your computer and use it in GitHub Desktop.
Save djouallah/822542e6d043148a293fde380a0cfff9 to your computer and use it in GitHub Desktop.
library(readxl)
library(tidyverse)
df1 <- read_excel("/ACTUAL/tracker_Register.xlsx")
df2 <- select(df1,'Row ID','Panel Qty',Accepted, Tracker)
df3 <- gather(df2,category,date,-"Row ID",-"Panel Qty")
df4 <- filter(df3,!is.na(date))
@MilesMcBain
Copy link

MilesMcBain commented Feb 22, 2019

In answer to your question, I wouldn't call this 'bad practice' - there are worse things than this, but it does have the unfortunate feature of meaningless intermediate variable names that distract from what is goin on.

I find variable names are a nice opportunity to communicate what is happening, and the pipe lets use them only when we want to. So I would certainly sympathise with not using one single chain - that can get just as unwieldy.

In this case the intermediate case looks nice to me:

library(readxl)
library(tidyverse)
tracker_data <- 
    read_excel("/ACTUAL/tracker_Register.xlsx") %>%
    select('Row ID','Panel Qty',Accepted, Tracker)

tracker_data_long <-
    tracker_data %>%
    gathercategory,date,-"Row ID",-"Panel Qty") %>%
    filter(!is.na(date))

Edit: accidentally copy pasted the df1,2,3 etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment