This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Via Stack Overflow | |
| # https://stackoverflow.com/questions/11130156/suppress-stdout-stderr-print-from-python-functions | |
| from contextlib import contextmanager,redirect_stderr,redirect_stdout | |
| from os import devnull | |
| @contextmanager | |
| def suppress_stdout_stderr(): | |
| """A context manager that redirects stdout and stderr to devnull""" | |
| with open(devnull, 'w') as fnull: | |
| with redirect_stderr(fnull) as err, redirect_stdout(fnull) as out: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(dplyr) # Helps manipulate data | |
| # Let's create example datasets | |
| records <- data.frame( | |
| user_id = c(1, 2, 3, 4, 5), | |
| location = c("A", "B", "C", "C", "D") | |
| ) | |
| # user_id location | |
| # 1 1 A | |
| # 2 2 B |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pandas as pd | |
| from io import StringIO | |
| params_df = pd.read_csv( | |
| StringIO( | |
| "parameter,value\ntheta,0.1\nbeta,0.5" | |
| ) | |
| ) | |
| params_df | |
| # parameter value |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #'@title Pipe-friendly (simplified) prop.table | |
| #'@description \code{prop_table} Computes proportions similiar to prop.table using \code{dplyr} functions. | |
| #'@param dat The data used for the computation. | |
| #'@param vars The columns to create aggregate counts of. | |
| #'@param na.rm Whether to remove missing values or not. Default is \code{FALSE}. | |
| #'@return A \code{data.frame} with the counts and proportions by \code{vars}. | |
| #' | |
| #'@author vikjam | |
| #' | |
| #'@examples |
OlderNewer