FileAttachment() can't load from external drive in Quarto

On my Windows machine I’m trying to read a .csv into an Observable chunk in a Quarto document. The file is in an external drive called ‘Z:’. But the FileAttachment call seems to always append ‘C:’ to the filepath, no matter what I do.

So for example, if I call:

dat = FileAttachment("Z:/my-file.csv").csv({ typed: true })

It appends the filepath to the root directory of my Quarto project, so it fails to find the file:

ERROR: The filename, directory name, or volume label syntax is incorrect. (os error 123), stat 'C:\Users\arand\Documents\analysis\myproject\Z:\myfile.csv'

And if I do a long chain of '…/'s to go up a bunch of levels, it always still appends ‘C:’ to the filepath. For example:

dat = FileAttachment("../../../../../../../../../Z:/my-file.csv").csv({ typed: true })

Returns:

ERROR: The filename, directory name, or volume label syntax is incorrect. (os error 123), stat 'C:\Z:\myfile.csv'

Hi Alex!

Quarto does things a bit differently than Observable, so you might have better luck finding an answer by reaching out to that team specifically. I see that there is a FileAttachment method referenced in the code cited in this thread (though the discussion focuses on a different issue):

…In native Observable, FileAttachments is a specific method for files that are uploaded into a notebook. References to local files work a bit differently. When working with local files, I find that the easiest way is to to create an input that accepts any file, and then to use that to select the one I want. The pattern for a CSV would therefore be something like:

viewof file = Inputs.file()

followed by selecting the CSV, then parsing it as:

parsedFile = file.csv()

… From there, you can reference parsedFile in your Quarto doc.

The Observable docs on file inputs are here: File Input / Observable Inputs / Observable | Observable

And for FileAttachments:

If this approach is not helpful for you, then you’d likely need help from the Quarto team. The issues you are facing with the C:\ vs. Z:\ path prefix appear to be introduced there.

Thanks Aaron, this is helpful information.

The idea is to render a document for a client based on private data stored on my org’s server, so the Inputs.file() isn’t a viable solution in this case. I’ll have a look around Quarto forums to see if this is mentioned anywhere.

1 Like