Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Long hyperlinks prevent workbook from loading on Windows #753

Closed
olivroy opened this issue Aug 22, 2023 · 5 comments
Closed

Long hyperlinks prevent workbook from loading on Windows #753

olivroy opened this issue Aug 22, 2023 · 5 comments

Comments

@olivroy
Copy link
Collaborator

olivroy commented Aug 22, 2023

image

test-long-hl.xlsx

wb_load("test-long-hl.xlsx")
#> Error in basename(xml_relship$Target) : path too long

image

# To circumvent having long URL in a path or hyperlink
basename_long <- function(x) {
  # I am seeing this for paths longer than 260 on Window
s
  if (any(nchar(x) > 250)) {
    x <- stringi::stri_sub(x, from = -255L) # Cut the begining of the path
  }

  basename(x)
}
# The link is the following
a_long_hl_from_google_search <- "https://www.google.com/search?q=a+very+long+hyperlink+from+a+google+search+aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa&sca_esv=559161978&sxsrf=AB5stBh3R0RwFy8QBN-mAmP3mYzwqhsCqw%3A1692733190678&ei=Bg_lZKz1KJ6I0PEPuYq-8A8&ved=0ahUKEwiskJ7EgvGAAxUeBDQIHTmFD_4Q4dUDCA8&uact=5&oq=a+very+long+hyperlink+from+a+google+search+aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa&gs_lp=Egxnd3Mtd2l6LXNlcnAiVGEgdmVyeSBsb25nIGh5cGVybGluayBmcm9tIGEgZ29vZ2xlIHNlYXJjaCBhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYTIFECEYoAEyBRAhGKABMgUQIRigATIFECEYoAFI2RFQkQFYxBBwAXgBkAEAmAG-AqAByAyqAQUyLTUuMbgBA8gBAPgBAcICChAAGEcY1gQYsAPiAwQYACBBiAYBkAYC&sclient=gws-wiz-serp&safe=active&ssui=on"

https://blog.r-project.org/2023/03/07/path-length-limit-on-windows/index.html

@JanMarvin
Copy link
Owner

Ah I see, hm, it's possibly a windows only restriction. R-core was messing with path length in Windows not to long ago. We don't have to use Basename() it was simply a convenient function, but we can use whatever function to get the base name. A small regex should do the trick.

@JanMarvin
Copy link
Owner

Loads fine on Mac. We can use sub(".*/([^/]+)$", "\\1", path) instead. It's way slower, but we have to use something

@olivroy
Copy link
Collaborator Author

olivroy commented Aug 22, 2023

What about?

# only go there if error?
basename2 <- function(x) {
 tryCatch(basename(x), error = function(e) sub(".*/([^/]+)$", "\\1", x))
}

Edit: I can open a PR if you want.

@JanMarvin
Copy link
Owner

Nah, I'll think of something.

@olivroy olivroy changed the title Long hyperlinks prevent workbook from loading Long hyperlinks prevent workbook from loading on Windows Aug 22, 2023
@olivroy
Copy link
Collaborator Author

olivroy commented Aug 23, 2023

Closed by #755

@olivroy olivroy closed this as completed Aug 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants