所以我在文件夹中有一个 R 包/项目。该包/项目是在没有 .Rproj 文件的情况下创建的。
如何追溯为该包/项目创建该文件?
h <- function(x) {
x <- 10
UseMethod("h")
}
h.character <- function(x){ paste("char", x)}
h.numeric <- function(x) { paste("num", x)}
h("a")
Run Code Online (Sandbox Code Playgroud)
上面的代码将输出:
[1] "char a"
Run Code Online (Sandbox Code Playgroud)
我的演绎推理,从下面来看,输出应该是“char 10”。
根据 UseMethod 的文档:
找到调用函数(通用函数)的上下文:这为我们提供了原始调用的未计算参数。
评估用于调度的对象(通常是参数),并找到一个方法(可能是默认方法)或抛出错误。
创建一个用于评估该方法的环境,并将特殊变量(见下文)插入该环境中。还要复制泛型环境中非形式(或实际)参数的任何变量。
将参数列表修复为与方法的形式匹配的调用参数。
如果我理解正确的话,在步骤 2 中,x 将被评估为“a”。但随后在步骤 3 中,另一个值为 10 的变量 x 被插入到环境中以执行该方法。
现在不会将 x 覆盖为 10 吗?最后在步骤 4 中,参数与方法的参数相匹配。因此 x(即 10)现在是该方法的参数。
我做错了什么
test_1 :: Int -> Int
test_1 y = 5 * 10 ^ (ceiling ( logBase 10 y ) ) + 100
Run Code Online (Sandbox Code Playgroud)
这是错误消息:
parse.hs:23:22: error:
• No instance for (RealFrac Int) arising from a use of ‘ceiling’
• In the second argument of ‘(^)’, namely
‘(ceiling (logBase 10 y))’
In the second argument of ‘(*)’, namely
‘10 ^ (ceiling (logBase 10 y))’
In the first argument of ‘(+)’, namely
‘5 * 10 ^ (ceiling (logBase 10 y))’
parse.hs:23:32: error:
• No …Run Code Online (Sandbox Code Playgroud) Fx=purrr::map(CDF, ~ tibble(
severity=severities$severity,
inclusive=severities$inclusive,
Fx=.x(severities$severity, severities$inclusive))))
Run Code Online (Sandbox Code Playgroud)raw_df <- tibble::tribble(
~"segment", ~"limit", ~"attach", ~"pct_written", ~"premium", ~"product", ~"lalae_ratio",
"", 50000, 1000, 0.5, 273456, "prod1", 0.65,
"", 20000, 2000, 0.5, 285760, "prod2", 0.65,
"", 2e+05, 3000, 0.5, 956456, "prod3", 0.65,
"", 10000, 300, 0.5, 90890, "prod4", 0.65)
Run Code Online (Sandbox Code Playgroud)我可以猜测它,但我对它的作用没有准确的定义。
这不同于:
dependent_variable ~ independent_variables
Run Code Online (Sandbox Code Playgroud) 所以目前,我有 ubuntu 19。它默认带有 python 3.7.5。我需要降级到 3.6.5。
编辑:
我正在使用 virtualenv
在我的 VS Code 的 Linux 版本中,当我按下该Alt键时,它会聚焦在菜单栏的“文件”选项卡上。不知道我是如何做到这一点的。以前不是这样的。
我如何禁用此功能?
以下是我的自定义模态组件的定义方式:
function Modal({ open, set_open, children }) {
const modal_ref = useRef(null);
useEffect(() => {
if (open) {
modal_ref.current.style.display = "block";
} else {
modal_ref.current.style.display = "none";
}
}, [open]);
return ReactDom.createPortal(
<div className="modal-container" ref={modal_ref}>
<div className="modal-content">{children}</div>
</div>,
document.getElementById("root")
);
}
Run Code Online (Sandbox Code Playgroud)
组件的 Children 属性将包含工具提示。或者实际上可能是孙子。
但无论如何,它都应该出现,不是吗?
它造成的问题是显而易见的。即使用户在复选框之外单击,它仍然会更改框值。
目标是消除该空间。
<FormControlLabel
style={{ height: "25px" }}
control={<Checkbox size="small" style={{ width: "20px" }} />}
label={
<Box component="div" fontSize={10}>
label
</Box>
}
/>
Run Code Online (Sandbox Code Playgroud)
请注意,width: "20px"没有任何效果。
每次Comp重新渲染,rand都会有不同的值。会触发吗useEffect?
function Comp({}) {
const rand = Math.random();
useEffect(() => {
// do stuff
}, [rand])
}
Run Code Online (Sandbox Code Playgroud) r ×3
reactjs ×3
javascript ×2
linux ×2
material-ui ×2
css ×1
devtools ×1
frontend ×1
haskell ×1
html ×1
modal-dialog ×1
popup ×1
python ×1
r-package ×1
rstudio ×1
tidyverse ×1
ubuntu ×1
virtualenv ×1