0

I am looking for importing a database into R Studio without having the sentences been compacted in one line, can someone help?

Example: In a single excel cells I have the following:

 She went on holiday
 He decided to eat an apple

Whereas in R Studio when I import the database I get:

 She went on holiday He decided to eat an apple

The code I am using for importing is:

df <- as.data.frame(read_excel("/mypath.xlsx"))

What I have and would like to keep the format on R:

enter image description here

zx8754
  • 52,746
  • 12
  • 114
  • 209
Akibaida
  • 37
  • 6
  • Can you post output of `dput(df)` ? – zx8754 Mar 29 '22 at 10:49
  • What do you see when you run: `df[, 2]`. – zx8754 Mar 29 '22 at 10:50
  • 1
    newline character is still there, it is about how we print it, see related post: https://stackoverflow.com/q/4071586/680068 – zx8754 Mar 29 '22 at 10:51
  • @zx8754 when I do `dput(df)` I get the the following: `e.g 'Column2' = c( Lei è andata in vacanza Lui ha mangiato una mela, Elle est aller en vacance il a mangè une pomme, ... ) ` Similarly when I do `df[,2]` I get: `[1] Lei è andata in vacanza Lui ha mangiato una mela [2] Elle est aller en vancace Il a mangè une pomme [3] ...` – Akibaida Mar 29 '22 at 12:05
  • I see, then you don't have the [newline character](https://support.microsoft.com/en-us/office/start-a-new-line-of-text-inside-a-cell-in-excel-33e41eab-8b5e-4193-93d6-9a06ecf812b3) `"\n"` in your Excel sheet. – zx8754 Mar 29 '22 at 12:08
  • @zx8754 I just included it but the outcome is the same. I am printing with `cat` (since in a rmarkdown), and I tried as well `cat(df[1,2],"\n")` but nothing has changed. However, I think it is going in the right way... any other suggestions? – Akibaida Mar 29 '22 at 12:29
  • @zx8754 actually I believe now that the issue is linked to rmarkdown since I am getting the error "LaTex failed to compile" pointing at the first sentence ending with `"\n"` – Akibaida Mar 29 '22 at 12:37
  • 1
    @zx8754 issue solved, need to use `\linebreak` instead of `\n`. Thanks a lot for your help! – Akibaida Mar 29 '22 at 12:42

0 Answers0