Notion Answers

Help between Notion users


Register & Ask

It's free & easy

Get answers

Answers, votes & comments

Vote and select answers

Receive points, vote and give the solution

Question

1vote

copy R code to Notion with right format

I have a block of R code looks like this:

replicates <- list()
data_path <- "D:/data"

file_list <- list.files(data_path, pattern = "\\.rds$", full.names = TRUE)

for (file_path in file_list) {
  loaded_data <- readRDS(file_path)

  extracted_list <- loaded_data[[1]]$my_data

  # Append the extracted list to the combined_list
  replicates <- c(replicates, list(extracted_list))
}

however when I try to copy this block to Notion, the format becomes so weird with only one line code, like this:

replicates <- list()data_path <- "D:/data" file_list <- list.files(data_path, pattern = "\\.rds$", full.names = TRUE) #here comes the rest of the original code, still in this line, I delete them

It works well on Windows, but not the Mac that I am using now. I have no idea how to fix it. I hope someone can help me out there, thanks!

1 Answer

0vote

polle Points78860

When you hover over a code block in Notion, at the top left you can select languages.

Just select the correct one and the code will display in multiple lines as you need.

0vote

yang commented

Sorry that I didn't make it clear. I did it but it still shows in one line. I tried it on windows it works.

0vote

yang commented

I also tried the top right three dots, choosing "Wrap code". It shows in multiple lines but a messy format.

0vote

polle commented

I just tested in Mac and it works fine as well.

Try updating the Notion App to the latest version, that may be the problem.

1vote

yang commented

I created a page by hitting the keyboard and choosing "/Page", then I started my notes, and I needed to add a the block of my R code, it's a part of my notes. Then I did "/Code", changed the language to "R", and copy paste.

0vote

polle commented

That is the correct way of doing it. Try updating the app as I said above or you can select another language to see if that works better.

0vote

yang commented

The version is 2.2.1 now, the latest one. The problem is still there, but thanks anyway. I think I need to do it manually or switch to windows.

0vote

polle commented

Strange, actually I am not able to display it in one line, no matter which language I choose.

In the Help menu try: Troubleshooting > Reset and Erase all local data.

That is the last one I can think that may fix the issue.

1vote

yang commented

Same :(. Thank you so much anyway. (I am not able to show it multiple lines no matter which language I choose)

0vote

polle commented

Glad to help and it is strange that it works differently for people, maybe a Notion bug that for sure will be fixed in new versions.

Please log in or register to answer this question.

...

Welcome to Notion Answers, where you can ask questions and receive answers from other members of the community.

Please share to grow the Notion Community!

Connect