如@Yihui的4.7 Verbatim code chunks的R Markdown Cookbook所示,我们可以显示逐字内联表达式,
//This working code is for windows hdc mouse coords gives the angle back that is used in windows. It assumes point 1 will be your origin point
// Tested and working on VS 2017 using 2 mouse coordinates in hdc.
//
//code to call our function.
float angler = get_angle_2points(Point1X, Point1Y, Point2X, Point2Y);
// Takes 2 Window coords(points), turns them into vectors using the origin and calculates the angle around the xaxis between them.
// This function can be used for any hdc window. Ie 2 mouse points.
float get_angle_2points(int p1x, int p1y, int p2x,int p2y)
{
//Make point1 the origin, make point2 relative to the origin so we do point1 - point1, and point2-point1,
//since we dont need point1 for the equation to work, the equation works correctly with the origin 0,0.
int deltaY = p2y - p1y;
int deltaX = p2x - p1x; //Vector 2 is now relative to origin, the angle is the same, we have just transformed it to use the origin.
float angleInDegrees = atan2(deltaY, deltaX) * 180 / 3.141;
angleInDegrees *= -1; // Y axis is inverted in computer windows, Y goes down, so invert the angle.
//Angle returned as:
// 90
// 135 45
//
// 180 Origin 0
//
// -135 -45
//
// -90
// returned angle can now be used in the c++ window function used in text angle alignment. ie plf->lfEscapement = angle*10;
return angleInDegrees;
}
,例如,在我们的RMarkdown输出中。
但是,此`r knitr::inline_expr("coef(summary(model))")`
无法解析带有双引号的代码,例如
knitr::inline_expr()
。
那么,当我想演示包含这样特殊字符的逐字记录时该怎么办?
`r knitr::inline_expr("coef(summary(model))["(Intercept)", "Estimate"]")`
答案 0 :(得分:4)
您可以转义双引号:
---
title: "Untitled"
author: "CLRR"
date: "2020/6/20"
documentclass: article
output:
bookdown::pdf_document2:
latex_engine: xelatex
keep_tex: TRUE
---
This verbatim can appear in the output:
`r knitr::inline_expr("coef(summary(model))[\"(Intercept)\", \"Estimate\"]")`
在注释中,@ monte提供了另一种解决方案,即交替使用单引号和双引号:knitr::inline_expr('coef(summary(model))["(Intercept)", "Estimate"]')