这里有一些编写R代码1,2和3的样式指南。它们都处理了我可以遵循的相对“不错”的示例。但是,让我粘贴一些我正在R中使用的实际代码:
mutate(DCloDate = min(Date),
AgeEOM = if_else(Type == "Date Created", as.integer(as.Date(ceiling_date(Month, unit = "month")) - days(1) - Date), -1L * as.integer(as.Date(ceiling_date(Month, unit = "month")) - days(1) - DCloDate))) %>%
这东西只是一个怪物。这是我尝试在文本编辑器上将宽度保持在80个字符以下的几种尝试,似乎一个接一个的错误选择。我可以将这些代码混乱转换为易于阅读的代码的客观方法是什么?
这是我需要的缩进和全部。谢谢。
# Attempt 1
mutate(
DCloDate = min(Date),
AgeEOM = if_else(
Type == "Date Created",
as.integer(as.Date(ceiling_date(Month, unit = "month")) - days(1) - Date),
-1L * as.integer(as.Date(
ceiling_date(Month, unit = "month")) - days(1) - DCloDate))) %>%
# Attempt 2
mutate(DCloDate = min(Date),
AgeEOM = if_else(Type == "Date Created",
as.integer(as.Date(ceiling_date(Month,
unit = "month")) -
days(1) - Date),
-1L * as.integer(as.Date(ceiling_date(Month,
unit = "month")) -
days(1) - DCloDate))) %>%
# Attempt 3
mutate(DCloDate = min(Date),
AgeEOM = if_else(
Type ==
"Date Created",
as.integer(as.Date(ceiling_date(Month, unit = "month")) -
days(1) - Date),
-1L * as.integer(as.Date(ceiling_date(Month, unit = "month")) -
days(1) -
DCloDate))) %>%
# Attempt 4, 5, 6 ...
just gets worse and worse
您是否尝试过在RStudio中选择全部,然后按Ctrl-Shift-A自动重新格式化代码?