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

DESCRIPTION on mounted folders #495

Closed
gdkrmr opened this issue Aug 25, 2016 · 5 comments
Closed

DESCRIPTION on mounted folders #495

gdkrmr opened this issue Aug 25, 2016 · 5 comments

Comments

@gdkrmr
Copy link

gdkrmr commented Aug 25, 2016

Situation:

Ubuntu 16.04, latest R and roxygen2 from CRAN and a Package in a folder mounted with sftp via gnome virtual file system

A call to roxygen2::document() produces a garbage DESCRIPTION file: instead of appending it overwrites from the beginning. The problem is R and writing to connections

 for(i in 1:10){cat(i, file = "/mounted/folder/test2", append = TRUE)}

gives a file that reads 10 and not 1 2 ... 10

Solution, open the file only once:

assignInNamespace(
    "write.description",
    function(desc, file = "") {
        con <- if(file != ""){
            file(file, "w")
        } else {
            ""
        }

        mapply(roxygen2:::cat.description, names(desc), desc, MoreArgs = list(file = con))

        if(inherits(con, "connection")) close(con)

        invisible()
    },
    "roxygen2"
)

The post that helped me with this can be found here:
https://stackoverflow.com/questions/24927041/r-writeappend-true-overwrites-file-contents

@gdkrmr
Copy link
Author

gdkrmr commented Aug 26, 2016

I did some more checking with

for(i in 1:10){cat(i, file = "/mounted/folder/test2", append = TRUE)}
  • A mapped network drive on Windows 7 and R 3.2.5 works fine.
  • A samba share on a Mac works fine.
  • A samba share on Ubuntu 16.04 works fine.
  • An sftp share on Ubuntu 16.04 does not work, replicated on 2 machines.

@hadley
Copy link
Member

hadley commented Aug 29, 2016

This is a bug with R — can you please report on R-devel?

@hadley hadley closed this as completed Aug 29, 2016
@eddelbuettel
Copy link
Contributor

eddelbuettel commented Aug 30, 2016

Nope.

(r-devel sent him to r-sig-debian where I just conjectured that R has nothing to do with this. The 'append' property is not being honoured by the sftp-based filesystem, which is not the fault of the client.)

I would suggest to work around it. Create the DESCRIPTION file somewhere else -- say in /tmp where the write and append semantics work. Then copy the final file.

@gdkrmr
Copy link
Author

gdkrmr commented Aug 30, 2016

you can change the roxygen2:::write.description as above and it works fine.
If anyone should ever come across the same isse, here is how I resolved it for me:

I created a file named .Rprofile in the package root folder (which is the working directory for the R process) with the following content:

.First <- function() {
    requireNamespace("roxygen2")
    unlockBinding("write.description", asNamespace("roxygen2"))
    assign(
        "write.description",
        function(desc, file = "") {
            con <- if(file != "") file(file, "w") else ""

            mapply(roxygen2:::cat.description, names(desc), desc, MoreArgs = list(file = con))

            if(con != "") close(con)

            invisible()
        },
        envir = asNamespace("roxygen2")
    )
    lockBinding("write.description", asNamespace("roxygen2"))
}

@hadley
Copy link
Member

hadley commented Aug 30, 2016

This will not work in the future because write.description has been removed. But I don't think the functions from the desc package will have the same problem.

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

3 participants