Categories
Mastering Development

data.table – split data.table into elements of a lists using ~ var|factor – cast / dcast

I have a large data.table which I am using for subsequent analysis on different levels of the data. In order to avoid repetitive code, I would like to break my data.table into smaller chunks and save them as (elements of) lists. Couple of days ago I have seen a post where something like this was […]

Categories
Linux Mastering Development Ubuntu

Error on videos (.mkv) after software upgrade

My system: Laptop Dell inspiron 15 3000 RAM: 16 GB SSD 480 GB Kingston Intel Core i3 7th Generation OS: Ubuntu 18.04 with Software and System Updates Web Browser: Mozilla Firefox, Google Chrome, Palemoon. All latest. Terminal emulator: Yakuake, gnome-terminal. Other Terminal: TTY1 Internet service provider connection speed: 100 Mbps (asymmetric) The upgrade Just recently […]

Categories
Development

A simple reproducible example to pass arguments to data.table in a self-defined function in R

I have been googling this answer for a few hours. A lot of people have asked similar questions, but I did not find either a simple enough question or a straightforward answer. Here is my approach: Assume that I want to do a simple group by in data.table: library(data.table) mtcars = data.table(mtcars) mtcars[,sum(mpg), gear] # […]

Categories
Development

AWS Lambda for generate thumbnail save empty file

I need to create aws lambda for creating thumbnail from video by using ffmpeg, which is saved on S3 and this thumbnail saved into S3 too. I downloaded ffmpeg from https://johnvansickle.com/ffmpeg/ page, set ffmpeg into nodejs file and send it into .zip. From this zip file I created ffmpeg layer. After that I connect my […]

Categories
Development

Combine labels with `geom_text_repel`?

How would I create a label that accounts for two points? In this example I am interested in making a label that is the sum of the the “6” and the “8” bars and has a line pointing to each of them. Currently I have: library(tidyverse) library(ggrepel) mtcars %>% group_by(cyl) %>% summarise(mpg = median(mpg)) %>% […]

Categories
Development

How to plot multiple y axes with plotly in R for loop

I’m trying to use a for loop to define multiple y axes in plotly graph in R. Below is an example. Does anyone have any suggestions or experience with getting something like this to work? #example of dataset of plotly to plot multiple y axes in for loop library(plotly) len = length(names(mtcars)) names = names(mtcars) […]

Categories
Development

Why do ‘if’ statements including arguments don’t work in ggplot geoms? [on hold]

Why do the following won’t work? ggplot(mtcars,aes(x=wt,y=mpg)) + geom_smooth({if (T) (“colour=’red'”)}) ggplot(mtcars,aes(x=wt,y=mpg)) + geom_smooth(ifelse(T,(“colour=’red'”))) ggplot(mtcars,aes(x=wt,y=mpg)) + geom_smooth(switch(T,(“colour=’red'”))) They all output this: Error: `mapping` must be created by `aes()` What would be a workaround? Edit: The proposed answers suggested to put the if statement after the named colour argument. The problem is that even if I […]

Categories
Development

Save several tables and plots into multi-page PDF

I have tried to export the plots and tables in my Shiny app to PDF report using R Markdown but it didn’t work. I thought about exporting them to PDF document following this nice answer. As I have several plots and tables, they won’t fit in one page as shown in this this answer. For […]

Categories
Development

Assign stable colors to ggplot when reordering and subsetting

In a shiny app, I let users subset data, and then create a plot in which a categorical variable is reordered from higher to lower according to the value of another variable and displayed following the user input. I would like color and fill to be linked to the category variable irrespective of the order. […]