I've just noticed a very weird behavior in the dummies
package of R when knitted in .Rmd
. Here's the reproducible example.
---
title: "Dummies Package Behavior"
author: "Kim"
date: '`r Sys.Date()`'
output:
pdf_document:
toc: yes
toc_depth: '3'
---
Load the libraries
```{r}
library(tidyverse)
library(dummies)
```
Main data wrangling
```{r}
df <- data_frame(year = c(2016, 2017, 2018))
temp <- dummy(df$year)
temp <- as_data_frame(temp)
df <- bind_cols(df, temp)
```
View output
```{r}
df
```
What I'm expecting to see when I view the df
are nice 0-1 columns of year2016
, year2017
, and year2018
, which is the normal behavior for the dummies
package.
When you knit this R Markdown document in RStudio, it instead brings out the following: C:/Users/Kim/Desktop/dummies.Rmd2016
, C:/Users/Kim/Desktop/dummies.Rmd2017
, and C:/Users/Kim/Desktop/dummies.Rmd2018
. That is, it uses the whole document address to make the column names.
I don't understand why such behavior occurs. Obviously, I want to have column names as year2016
, year2017
, and year2018
.