add ascii qr code to alpine signature file - qr-code

I'm trying to add an ASCII qr code to the signatura file (~/.signature).
The code is generated via qrencode, and in alpine it looks like this:
But after sending the email, for instance, in gmail it looks like this:
The signature file can be found here: signature file
Is it possible to fix this?

Use this:
##############      ##  ##    ##########    ##############
##          ##  ####    ####  ##    ##  ##  ##          ##
##  ######  ##  ##    ####  ########  ##    ##  ######  ##
##  ######  ##    ##  ####    ##    ####    ##  ######  ##
##  ######  ##  ####    ######  ######      ##  ######  ##
##          ##  ##  ##  ####  ####  ######  ##          ##
##############  ##  ##  ##  ##  ##  ##  ##  ##############
                ##  ##  ##  ####  ########                
####  ##    ####  ####      ##  ##  ####    ######  ####  
  ##  ######      ####    ##              ####    ##    ##
######  ######  ##          ##  ####  ########    ######  
####  ##          ##      ####  ##  ##    ##  ####  ####  
####      ####      ####  ####  ####  ########    ##  ####
  ##      ##  ##    ##      ##        ######  ##          
      ##  ########  ########      ####  ##        ########
        ####    ####  ##  ##############          ##  ##  
    ##  ##  ####        ##    ##  ##    ####  ##      ##  
  ##  ##  ##  ##      ##    ##    ##      ######  ##    ##
##          ##  ##  ##  ##        ##    ####  ##      ####
      ######    ####        ##  ####    ####          ####
##  ##    ####        ########      ##  ##########  ##    
                ####    ####    ##    ####      ##  ######
##############  ##  ##  ####    ####    ##  ##  ##    ##  
##          ##    ######  ##  ##    ##  ##      ##########
##  ######  ##      ##  ####  ######    ##########    ##  
##  ######  ##  ####    ######        ##    ##  ########  
##  ######  ##        ##  ##      ##  ##        ######  ##
##          ##  ##    ######  ######  ########  ##    ##  
##############  ##  ######  ##  ####    ##########        
Instead of:
############## ## ## ########## ##############
## ## #### #### ## ## ## ## ##
## ###### ## ## #### ######## ## ## ###### ##
## ###### ## ## #### ## #### ## ###### ##
## ###### ## #### ###### ###### ## ###### ##
## ## ## ## #### #### ###### ## ##
############## ## ## ## ## ## ## ## ##############
## ## ## #### ########
#### ## #### #### ## ## #### ###### ####
## ###### #### ## #### ## ##
###### ###### ## ## #### ######## ######
#### ## ## #### ## ## ## #### ####
#### #### #### #### #### ######## ## ####
## ## ## ## ## ###### ##
## ######## ######## #### ## ########
#### #### ## ############## ## ##
## ## #### ## ## ## #### ## ##
## ## ## ## ## ## ## ###### ## ##
## ## ## ## ## ## #### ## ####
###### #### ## #### #### ####
## ## #### ######## ## ########## ##
#### #### ## #### ## ######
############## ## ## #### #### ## ## ## ##
## ## ###### ## ## ## ## ##########
## ###### ## ## #### ###### ########## ##
## ###### ## #### ###### ## ## ########
## ###### ## ## ## ## ## ###### ##
## ## ## ###### ###### ######## ## ##
############## ## ###### ## #### ##########
The difference is that the regular space character used in the second qrcode was replaced with the unicode U+2007 &#8199 in the first one, which is a different space character that happens to use the same space as #. As you can see it wasn't necessary even to blockquote them, their space was fixed by itself.
The problem here is that alpine sends text only emails (mime type text/plain) and gmail instead of showing it in a monospaced font, it shows it in Arial,Helvetica,sans-serif. If you open the "bad" email in any cli email client like Alpine it will be shown as "good", because cli are forced to use monoscpaced fonts by nature. Gmail has decided helvetica font family is better than monospaced, trading off this ability to handle better those "ascii art" emails.
Trying to force Alpine to send text/html emails by embedding HTML tags or trying to insert Content-Type: text/html; charset="UTF-8" in the message didn't work.
With this limitation, we still can take advantage of the great variety of symbols that unicode has to offer and choose a combination of black and white characters that solves this problem of having the same spacing for this font family Arial,Helvetica,sans-serif. By keeping your # as the black character in the QR Code and using U+2007 &#8199 Figure Space your problem is solved.
If you want to try other black characters like this one █ to make your QR-code more solid, you can try, but then you need to find a equally-spaced space character, and also test if the vertical proportions are ok. It is also good to check for different environments - windows with x fonts installed, mac with y fonts installed and linux with z fonts installed may have different opnions about the fonts Arial, Helvetica and sans-serif and their respective spacings.

By default, Gmail client limits the width of your text. You can adjust your email's inline styles to prevent text wrapping:
<table style="width: 100%; max-width: 600px; white-space: nowrap">
...
<table>

You can use <pre> which preformatted text which is to be presented exactly as written in the HTML file. You can learn more about at https://developer.mozilla.org/en-US/docs/Web/HTML/Element/pre
Thanks.

Related

Is it possible to run an Apollo model as a function? - gives errors about global environment

Let's say I have this Apollo model (from http://www.apollochoicemodelling.com/files/examples/4%20Ranking%20and%20rating/OL.r)
# ################################################################# #
#### LOAD LIBRARY AND DEFINE CORE SETTINGS ####
# ################################################################# #
### Clear memory
rm(list = ls())
### Load Apollo library
library(apollo)
### Initialise code
apollo_initialise()
### Set core controls
apollo_control = list(
modelName = "OL",
modelDescr = "Ordered logit model fitted to attitudinal question in drug choice data",
indivID = "ID",
outputDirectory = "output"
)
# ################################################################# #
#### LOAD DATA AND APPLY ANY TRANSFORMATIONS ####
# ################################################################# #
### Loading data from package
### if data is to be loaded from a file (e.g. called data.csv),
### the code would be: database = read.csv("data.csv",header=TRUE)
database = ?apollo_drugChoiceData
### for data dictionary, use ?apollo_drugChoiceData
# ################################################################# #
#### DEFINE MODEL PARAMETERS ####
# ################################################################# #
### Vector of parameters, including any that are kept fixed in estimation
apollo_beta = c(beta_reg_user = 0,
beta_university = 0,
beta_age_50 = 0,
tau_quality_1 =-2,
tau_quality_2 =-1,
tau_quality_3 = 1,
tau_quality_4 = 2)
### Vector with names (in quotes) of parameters to be kept fixed at their starting value in apollo_beta, use apollo_beta_fixed = c() if none
apollo_fixed = c()
# ################################################################# #
#### GROUP AND VALIDATE INPUTS ####
# ################################################################# #
apollo_inputs = apollo_validateInputs()
# ################################################################# #
#### DEFINE MODEL AND LIKELIHOOD FUNCTION ####
# ################################################################# #
apollo_probabilities=function(apollo_beta, apollo_inputs, functionality="estimate"){
### Attach inputs and detach after function exit
apollo_attach(apollo_beta, apollo_inputs)
on.exit(apollo_detach(apollo_beta, apollo_inputs))
### Create list of probabilities P
P = list()
### Calculate probabilities using Ordered Logit model
ol_settings = list(outcomeOrdered = attitude_quality,
utility = beta_reg_user*regular_user + beta_university*university_educated + beta_age_50*over_50,
tau = list(tau_quality_1, tau_quality_2, tau_quality_3, tau_quality_4),
rows = (task==1))
P[["model"]] = apollo_ol(ol_settings, functionality)
### Take product across observation for same individual
P = apollo_panelProd(P, apollo_inputs, functionality)
### Prepare and return outputs of function
P = apollo_prepareProb(P, apollo_inputs, functionality)
return(P)
}
# ################################################################# #
#### MODEL ESTIMATION ####
# ################################################################# #
model = apollo_estimate(apollo_beta, apollo_fixed, apollo_probabilities, apollo_inputs)
# ################################################################# #
#### MODEL OUTPUTS ####
# ################################################################# #
# ----------------------------------------------------------------- #
#---- FORMATTED OUTPUT (TO SCREEN) ----
# ----------------------------------------------------------------- #
apollo_modelOutput(model)
# ----------------------------------------------------------------- #
#---- FORMATTED OUTPUT (TO FILE, using model name) ----
# ----------------------------------------------------------------- #
apollo_saveOutput(model)
However, since I need to make many version of the same model with a very small change, I would love to make it into a function. Say like this:
Apollofunction <- function(beta,variable){
# ################################################################# #
#### LOAD LIBRARY AND DEFINE CORE SETTINGS ####
# ################################################################# #
### Clear memory
rm(list = ls())
### Load Apollo library
library(apollo)
### Initialise code
apollo_initialise()
### Set core controls
apollo_control = list(
modelName = "OL",
modelDescr = "Ordered logit model fitted to attitudinal question in drug choice data",
indivID = "ID",
outputDirectory = "output"
)
# ################################################################# #
#### LOAD DATA AND APPLY ANY TRANSFORMATIONS ####
# ################################################################# #
### Loading data from package
### if data is to be loaded from a file (e.g. called data.csv),
### the code would be: database = read.csv("data.csv",header=TRUE)
database = ?apollo_drugChoiceData
### for data dictionary, use ?apollo_drugChoiceData
# ################################################################# #
#### DEFINE MODEL PARAMETERS ####
# ################################################################# #
### Vector of parameters, including any that are kept fixed in estimation
apollo_beta = c(beta = 0,
beta_university = 0,
beta_age_50 = 0,
tau_quality_1 =-2,
tau_quality_2 =-1,
tau_quality_3 = 1,
tau_quality_4 = 2)
### Vector with names (in quotes) of parameters to be kept fixed at their starting value in apollo_beta, use apollo_beta_fixed = c() if none
apollo_fixed = c()
# ################################################################# #
#### GROUP AND VALIDATE INPUTS ####
# ################################################################# #
apollo_inputs = apollo_validateInputs()
# ################################################################# #
#### DEFINE MODEL AND LIKELIHOOD FUNCTION ####
# ################################################################# #
apollo_probabilities=function(apollo_beta, apollo_inputs, functionality="estimate"){
### Attach inputs and detach after function exit
apollo_attach(apollo_beta, apollo_inputs)
on.exit(apollo_detach(apollo_beta, apollo_inputs))
### Create list of probabilities P
P = list()
### Calculate probabilities using Ordered Logit model
ol_settings = list(outcomeOrdered = attitude_quality,
utility = beta*variable + beta_university*university_educated + beta_age_50*over_50,
tau = list(tau_quality_1, tau_quality_2, tau_quality_3, tau_quality_4),
rows = (task==1))
P[["model"]] = apollo_ol(ol_settings, functionality)
### Take product across observation for same individual
P = apollo_panelProd(P, apollo_inputs, functionality)
### Prepare and return outputs of function
P = apollo_prepareProb(P, apollo_inputs, functionality)
return(P)
}
# ################################################################# #
#### MODEL ESTIMATION ####
# ################################################################# #
model = apollo_estimate(apollo_beta, apollo_fixed, apollo_probabilities, apollo_inputs)
# ################################################################# #
#### MODEL OUTPUTS ####
# ################################################################# #
# ----------------------------------------------------------------- #
#---- FORMATTED OUTPUT (TO SCREEN) ----
# ----------------------------------------------------------------- #
apollo_modelOutput(model)
# ----------------------------------------------------------------- #
#---- FORMATTED OUTPUT (TO FILE, using model name) ----
# ----------------------------------------------------------------- #
apollo_saveOutput(model)
}
Then I could be able to call this apollo function with multiple variations:
Apollofunction(beta_reg_user, regular_user)
Apollofunction(etc, etc)
However, when I then try to run the function, it gives me the error Error in apollo_validateInputs() : No variable called database found in user workspace (i.e. global environment).
I then tried to upload the database in the global environment and delete the rm(list = ls()), but then I just get this error: Error in apollo_validateInputs() : No variable called apollo_beta found in user workspace (i.e. global environment). - so there seems to be a problem with how the function interacts with the global environment. Any way to change that? Maybe it has something to do with the use of "="?
The data is available at the link for OL - the csv file. http://www.apollochoicemodelling.com/examples.html

"Error in `[.data.frame`(database, , apollo_control$indivID) : undefined columns selected" in R studio

At this moment i want to create a model from apollo packages. I import the data from .txt file and want to create appollo_fixed variable.Then, this error message occured. (The data was imported succesfully)
apollo_inputs = apollo_validateInputs()
Error in [.data.frame(database, , apollo_control$indivID) :
undefined columns selected
The code I use is shown here,
rm(list = ls())
### Load libraries
library(apollo)
### Initialise code
apollo_initialise()
### Set core controls
apollo_control = list(
modelName ="MNL",
modelDescr ="Simple MNL model on mode choice data",
indivID ="id")
# ####################################################### #
#### 2. Data loading ####
# ####################################################### #
mydata <- read.table("/Documents/Travelmode_Final_project.txt", header=TRUE)
database = mydata
rm(mydata)
# ####################################################### #
#### 3. Parameter definition ####
# ####################################################### #
### Vector of parameters, including any that are kept fixed during estimation
apollo_beta=c(shuttlebus=0,
citybus=0,
bike=0,
ubike=0,
motorbike=0,
car=0,
mrt=0,
taxi=0,
b_SB_TC=0,
b_SB_TT=0,
b_CB_TC=0,
b_CB_TT=0,
b_B_TC=0,
b_B_TT=0,
b_UB_TC = 0,
b_UB_TT=0,
b_M_TC=0,
b_M_TT=0,
b_C_TC=0,
b_C_TT=0,
b_MRT_TT=0,
b_MRT_TC=0,
b_T_TT=0,
b_T_TC=0)
apollo_fixed = c("shuttlebus")
# ####################################################### #
#### 4. Input validation ####
# ####################################################### #
apollo_inputs = apollo_validateInputs()
Is there any solution I may need to change to solve this error? Or any potential reasons that may cause this error?

Creating an R markdown/notebook template file: can I define code chunks to be folded when the `.rmd` file is opened in Rstudio?

I'm creating a template file for R markdown / R notebook. There are several code chunks that I wish will remain folded when the .rmd is being opened. Is this possible?
Example
Let's say that we have the following code, and we save it (without the ##) into a file named my_file.rmd
## ---
## title: "R Notebook"
## output: html_notebook
## ---
## # step 0 -- my predefind functions
## ```{r my_func()}
## my_func <- function(x) {
## x + 1
## }
## ```
## ```{r my_func_2()}
## my_func_2 <- function(x) {
## x / 6
## }
## ```
## # step 1 -- your code here
## ```{r}
## ```
Is there a way we can open my_file.rmd — using RStudio — with the chunks {r my_func()} and {r my_func_2()} being folded upon opening the file?
You coud use code_folding: hide YAML combined with class.source = 'fold-show' for he chuncks you want to show, see:
---
title: "R Notebook"
output:
html_document:
code_folding: hide
---
# step 0 -- my predefined functions
```{r my_func()}
my_func <- function(x) {
x + 1
}
```
```{r my_func_2()}
my_func_2 <- function(x) {
x / 6
}
```
# step 2 -- your code here
```{r class.source = 'fold-show'}
my_func_3 <- function(x) {
x / 6
}
```
As long as you have a proper R chunks, you can fold the code inside the Rmd in Rstudio. I highly suggest you read up on knitr spin() too

Error in tapply(explanators_sub[, s], chosen, mean, na.rm = TRUE) : arguments must have same length

I know this question has been asked already but I do not have a tapply function in my code. Everything is actually totally new for me. I keep receiving this message after the line explanators = database[,c("gender","age","edu")]:
Error in tapply(explanators_sub[, s], chosen, mean, na.rm = TRUE) : arguments must have same length.
But I do not know what to do. I understand it's a problem of length in the data.
I tried:
choiceVar = database$chosen_veh [,c],
explanators = database[,c("gender","age","edu")]
But it is obviously wrong.
library(apollo)
library(readr)
### Clear memory
rm(list = ls())
# ################################################################# #
#### LOAD DATA AND APPLY ANY TRANSFORMATIONS ####
# ################################################################# #
database = read_delim("EV.txt", "\t", escape_double = FALSE, trim_ws = TRUE)
database$rowID = 1:nrow(database)
### Initialise code
apollo_initialise()
### Set core controls
apollo_control = list(
modelName ="first_MNL",
modelDescr ="Simple MNL model on EV car choice SP data",
indivID ="rowID",
panelData = FALSE
)
# ################################################################# #
#### ANALYSIS OF CHOICES ####
# ################################################################# #
choiceAnalysis_settings <- list(
alternatives = c(E=1, H=2, P=3),
avail = list(E=1, H=1, P=1),
choiceVar = database$chosen_veh,
explanators = database[,c("gender","age","edu")]
)
apollo_choiceAnalysis(choiceAnalysis_settings, apollo_control, database)
# ################################################################# #
#### DEFINE MODEL PARAMETERS ####
# ################################################################# #
### Vector of parameters, including any that are kept fixed in estimation
apollo_beta=c(asc_E = 0,
asc_H = 0,
asc_P = 0)
### Vector with names (in quotes) of parameters to be kept fixed at their starting value in apollo_beta, use apollo_beta_fixed = c() if none
apollo_fixed = c("asc_P")
# ################################################################# #
#### GROUP AND VALIDATE INPUTS ####
# ################################################################# #
apollo_inputs = apollo_validateInputs()
# ################################################################# #
#### DEFINE MODEL AND LIKELIHOOD FUNCTION ####
# ################################################################# #
apollo_probabilities=function(apollo_beta, apollo_inputs, functionality="estimate"){
### Attach inputs and detach after function exit
apollo_attach(apollo_beta, apollo_inputs)
on.exit(apollo_detach(apollo_beta, apollo_inputs))
### Create list of probabilities P
P = list()
### List of utilities: these must use the same names as in mnl_settings, order is irrelevant
V = list()
V[['E']] = asc_E
V[['H']] = asc_H
V[['P']] = asc_P
### Define settings for MNL model component
mnl_settings = list(
alternatives = c(E=1, H=2, P=3),
avail = list(E=1, H=1, P=1),
choiceVar = chosen_veh,
V = V
)
### Compute probabilities using MNL model
P[['model']] = apollo_mnl(mnl_settings, functionality)
### Take product across observation for same individual
#P = apollo_panelProd(P, apollo_inputs, functionality)
### Prepare and return outputs of function
P = apollo_prepareProb(P, apollo_inputs, functionality)
return(P)
}
# ################################################################# #
#### MODEL ESTIMATION ####
# ################################################################# #
model = apollo_estimate(apollo_beta, apollo_fixed, apollo_probabilities, apollo_inputs)
# ################################################################# #
#### MODEL OUTPUTS ####
# ################################################################# #
# ----------------------------------------------------------------- #
#---- FORMATTED OUTPUT (TO SCREEN) ----
# ----------------------------------------------------------------- #
apollo_modelOutput(model)
# ----------------------------------------------------------------- #
#---- FORMATTED OUTPUT (TO FILE, using model name) ----
# ----------------------------------------------------------------- #
apollo_saveOutput(model)
Do you have any idea how to solve it?
The data base is quite big but I could insert it in here if needed.

Excluding some patterned code in read_chunk knitr function in R

I'm using read_chunk function to read R code from external file. Sometimes I add comments for myself but I want to exclude those comments in my final document. I wonder how can the following pattern
###################################################
### code chunk number 1:
###################################################
can be excluded in read_chunk function.
###################################################
### code chunk number 1:
###################################################
## ---- Code1 ----
Some Code
###################################################
### code chunk number 2:
###################################################
## ---- Code2 ----
Some Code
###################################################
### code chunk number 3:
###################################################
## ---- Code3 ----
Some Code
###################################################
### The End
###################################################
Thanks in advance for your help.
I guess you can filter out the lines you don't want,
code <- "
###################################################
### code chunk number 1:
###################################################
## ---- Code1 ----
ls()
###################################################
### code chunk number 2:
###################################################
## ---- Code2 ----
ls()
###################################################
### code chunk number 3:
###################################################
## ---- Code3 ----
ls()
###################################################
### The End
###################################################
"
codelines <- readLines(textConnection(code))
# if the code is in file 'mycode.txt'
# codelines <- readLines('mycode.txt')
codelines <- codelines[!codelines == ""] # empty lines
keep <- !grepl("###", x=codelines) # comment lines
read_chunk(lines=paste(codelines[keep]))
knitr:::knit_code$get()
knitr:::knit_code$restore()

Resources