An R function with a parameter that accepts a data.frame column can’t evaluate the column argument until it is first ‘quoted’, followed by an ‘unquote’ within the dyplr function. ‘Quote’ a column using enquo(), then ‘unquote’ it using !!.
Add whitespace between RStudio markdown chunks
A little white space between R Markdown sections gives the reader a little pause in the story before changing the subject otherwise all the cells get smooshed together by default and it ends up looking like one long run-on sentence.
Add gradient colors to a bar chart with ggplot()
To emphasize value differences in a bar chart, using gradient colors is a nice option. ggplot makes it easy with scale_fill_gradient2().
Preserve structure when saving data to files in R
Writing data to a file using write.csv failes to retain column data types. A better way to save/restore data objects to/from files is by using RDS and RData.
ifelse alternative in R
Instead of a cumbersomely nested ifelse statement, use dplyr’s mutate and case_when functions instead.
replace_na not working
Convert data.frame factor columns to character columns before trying to replace NULL values.
Finding NULL values in R
Find NULLs in a dataframe using is.na().
Undo in RStudio
Ctrl-Z to the rescue. ‘nuf said.
Troubleshoot with `logging` instead of `print()`
Adding temporary print statements to troubleshoot Python code is quick and dirty. And messy. Incorporating logging into your code habit is a great alternative to relying on ad-hoc print statements that just need to get deleted later.
Save Google Colab notebook to HTML
Save a Google Colab notebook to another format, such as HTML or PDF.
GitHub too-big HTML preview
When HTML files on GitHub are too big to render, here’s a quick work-around.
Convert .py to .ipynb
Use p2j to convert Python source code to Jupyter Notebook.