- 不要让简单的方式复杂化
Here are a few possibilities for simplifying:
• Don’t use a list when an atomic vector will do.
• Don’t use a data frame when a matrix will do.
• Don’t try to use an atomic vector when a list is needed.
• Don’t try to use a matrix when a data frame is needed.
- 正确对待warning
- Figure out what the warning is saying.
- Figure out why the warning is triggered.
- Figure out the effect on the results of the computation (via deduction or experimentation).
- Given the result of step 3, decide whether or not the results will be erroneous.
- 几类错误
- 避免全局赋值<<- 风险的一种策略
将函数用local 定义在一个局部环境中,将相关计算的变量结果直接保存在局部,通过环境获取该变量: