简体   繁体   中英

Continue a file path in the next line in R

When a render this script with the RMarkdown, the path of a file exceeds the limit of the PDF.

df_reserva = read_excel('E:/OneDrive/FACULDADE/Semestre 6/Métodos Quantitativos Aplicados a Políticas Públicas e Sociais/Trabalho Final/Bases de Dados/forms.xlsx')

I want to add some line breaks , so the code looks like this

df_reserva = read_excel('E:/OneDrive/FACULDADE/Semestre 6/    
Métodos Quantitativos Aplicados a Políticas Públicas e Sociais/    
Trabalho Final/Bases de Dados/forms.xlsx')

Any tips here?

Does this work?

p1 <- 'E:/OneDrive/FACULDADE/Semestre 6/'
p2 <- 'Métodos Quantitativos Aplicados a Políticas Públicas e Sociais/'
p3 <- 'Trabalho Final/Bases de Dados/forms.xlsx'
df_reserva <- read_excel(paste0(p1, p2, p3))

You should use file.path() . For instance:

df_reserva = read_excel(file.path('E:/OneDrive/FACULDADE/Semestre 6',
                                  'Métodos Quantitativos Aplicados a Políticas Públicas e Sociais',
                                  'Trabalho Final/Bases de Dados/forms.xlsx')

If you use R > 4.1.0 you can also use basepipe ( |> ) to make it more readable by avoiding nested parenthesis:

file.path('E:/OneDrive/FACULDADE/Semestre 6',
          'Métodos Quantitativos Aplicados a Políticas Públicas e Sociais',
          'Trabalho Final/Bases de Dados/forms.xlsx') |>
    read_excel() -> df_reserva

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM